photo-gal.el 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. (defvar *photogal/operating-photo-dir* nil)
  2. (defvar *photogal/all-photos* nil)
  3. (defvar *photogal/operating-table* nil)
  4. (defun photogal-init-operating-table ()
  5. (setq *photogal/operating-table* (mapcar (lambda (photo)
  6. (cons (list 'photo) photo))
  7. *photogal/all-photos*)))
  8. (require 'transient)
  9. (define-derived-mode photogal-mode text-mode "photogal"
  10. "Major mode for grouping and labeling images.")
  11. (setq photogal-raw-tags '(("s" . "selfie") ("c" . "cityscape")))
  12. (defun photogal-auto-tags ()
  13. (let ((args (mapcar (lambda (tag) (list (car tag) " " (cdr tag))) photogal-raw-tags)))
  14. (vconcat (cons "Arguments"
  15. args))))
  16. (setq photogal-tags
  17. (photogal-auto-tags))
  18. (setq photogal-operations
  19. [["Operations"
  20. ("RET" "Next" photogal-next-file)
  21. ("P" "Previous" photogal-prev-file)
  22. ("A" "Add new tag" photogal-add-tag)]])
  23. (defvar photogal-default-directory "/Users/jwd/bench/photos/")
  24. (defun photogal (photo-dir)
  25. (interactive (list (read-directory-name "where are ur photos? "
  26. photogal-default-directory)))
  27. (message photo-dir)
  28. (let ((photo-files-directory (directory-file-name photo-dir)))
  29. (setq *photogal/operating-photo-dir* (concat photo-files-directory "-photogal"))
  30. (setq *photogal/all-photos* (photogal-all-photos)))
  31. (photogal-init-operating-table)
  32. (photogal-init (photogal-current-file))
  33. (photogal-categorize)
  34. )
  35. (transient-define-prefix photogal-categorize ()
  36. "Tag a photo."
  37. photogal-tags
  38. photogal-operations
  39. (interactive)
  40. (setq *photogal-current-file* (photogal-current-file))
  41. (transient-setup 'photogal-categorize))
  42. (defun photogal-all-photos ()
  43. (message *photogal/operating-photo-dir*)
  44. (directory-files *photogal/operating-photo-dir*
  45. t directory-files-no-dot-files-regexp))
  46. (defun photogal-current-file ()
  47. (car *photogal/all-photos*))
  48. (defun photogal-add-tags-to-file (file tag)
  49. (let ((tags (car (rassoc file *photogal/operating-table*))))
  50. (setcar (rassoc file *photogal/operating-table*) (cons tag tags))))
  51. (defun photogal-get-tags-for-file (file)
  52. (car (rassoc file *photogal/operating-table*)))
  53. (defun photogal-next-file ()
  54. (interactive)
  55. (let ((current-file (photogal-current-file)))
  56. (mapcar (lambda (t-arg) (photogal-add-tags-to-file current-file t-arg))
  57. (transient-args 'photogal-categorize))
  58. )
  59. (setq *photogal/all-photos*
  60. (append (cdr *photogal/all-photos*) (list (car *photogal/all-photos*))))
  61. (photogal-init (photogal-current-file))
  62. (photogal-categorize))
  63. (defun photogal-prev-file ()
  64. (interactive)
  65. (let ((current-file (photogal-current-file)))
  66. (mapcar (lambda (t-arg) (photogal-add-tags-to-file current-file t-arg))
  67. (transient-args 'photogal-categorize))
  68. )
  69. (setq *photogal/all-photos*
  70. (append (last *photogal/all-photos*) (butlast *photogal/all-photos*)))
  71. (photogal-init (photogal-current-file))
  72. (photogal-categorize))
  73. (defun photogal-init (photo-file-path)
  74. (let ((buf (get-buffer-create "photogal")))
  75. (with-current-buffer buf
  76. (photogal-mode)
  77. (erase-buffer)
  78. (insert "\n")
  79. (insert " ")
  80. (insert-image
  81. ;; (create-image (car photos) 'imagemagick nil :width (- (window-pixel-width) 75))
  82. (create-image photo-file-path
  83. 'imagemagick nil :height (/ (window-pixel-height) 2)))
  84. (insert "\n\n")
  85. (insert (format "%s" (photogal-get-tags-for-file photo-file-path)))
  86. )
  87. (switch-to-buffer buf)))
  88. (defun photogal-add-tag (new-tag new-tag-code)
  89. (interactive "sNew tag: \nsTag code: ")
  90. (setq photogal-raw-tags
  91. (cons (cons new-tag-code new-tag) photogal-raw-tags))
  92. (setq photogal-tags (photogal-auto-tags))
  93. (eval `(transient-define-prefix photogal-categorize ()
  94. "Tag a photo."
  95. ,photogal-tags
  96. ,photogal-operations
  97. (interactive)
  98. (setq *photogal-current-file* (photogal-current-file))
  99. (transient-setup 'photogal-categorize)))
  100. (transient-setup 'photogal-categorize))