photogal3.el 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. (defvar *photogal/photoreel* nil)
  2. (defvar *photogal/tags*
  3. '(
  4. ("e" . (name "spokane" ;; pg will not display
  5. parent ("L" . (name "Location")))) ;; differences in the
  6. ("n" . (name "new-york" ;; names of tag
  7. parent ("L" . (name "Locution")))) ;; parents. they will be
  8. ("e" . (name "emma-chamberlain" ;; considered the same.
  9. parent ("C" . (name "Celebrity"))))
  10. ("x" . (name "lil-nas-x"
  11. parent ("C" . (name "Celebrity"))))
  12. ("a" . (name "art"))
  13. ("c" . (name "cityscape"))
  14. ("f" . (name "family"))
  15. ("g" . (name "good"))
  16. ("h" . (name "screenshot"))
  17. ("l" . (name "politics"))
  18. ("m" . (name "meme"))
  19. ("o" . (name "computer"))
  20. ("p" . (name "portrait"))
  21. ("r" . (name "reaction-photo"))
  22. ("t" . (name "photography"))
  23. ("s" . (name "selfie"))))
  24. (define-derived-mode photogal-mode text-mode "photogal"
  25. "Major mode for grouping and labeling images.")
  26. (defun photogal-create-photo-roll (photo-dir)
  27. (defun photogalroll--all-photos (directory)
  28. "Give me a list of all the photos in my operating directory."
  29. (directory-files directory
  30. t directory-files-no-dot-files-regexp))
  31. (defun photogalroll--generate (destination-dir)
  32. (mapcar (apply-partially #'photogalroll--make-photo-entry
  33. destination-dir)
  34. (photogalroll--all-photos photo-dir)))
  35. (let ((destination-dir (concat photo-dir "-photogal"))
  36. (idx 0))
  37. (mapcar (lambda (photo) (photogal--set-index photo (cl-incf idx)))
  38. (photogalroll--generate destination-dir))
  39. ))
  40. (defun photogal-current-file (photoreel)
  41. "What is the file currently being operated on?"
  42. (car photoreel))
  43. (defun photogal-advance-file (photoreel)
  44. "Move forward by one photo."
  45. (append (cdr photoreel) (list (car photoreel))))
  46. (defun photogal-rewind-file (photoreel)
  47. "Reverse by one photo."
  48. (append (last photoreel) (butlast photoreel)))
  49. (defun photogal3 (photo-dir)
  50. (interactive (list (read-directory-name
  51. "where are ur photos? " photogal-default-directory)))
  52. (setq *photogal/photoreel* (photogal-create-photo-roll photo-dir))
  53. (photogal-render *photogal/photoreel*))
  54. (defun photogal-render (photoreel)
  55. (photogal-draw-buffer photoreel "photogal3" (photogal-top-level-tags) )
  56. )
  57. ;; // PHOTO DATAOBJECT \\ ;;
  58. (defun photogalroll--make-photo-entry (destination-dir filepath)
  59. `(filepath ,filepath
  60. tags ,nil
  61. name ,nil
  62. folders ,(list destination-dir)
  63. copy-to-dir ,nil
  64. index ,-1
  65. ))
  66. (defun photogal--get-filepath (photo)
  67. (plist-get photo 'filepath))
  68. (defun photogal--get-tags (photo)
  69. "What are all the tags for this file?"
  70. (plist-get photo 'tags))
  71. (defun photogal--set-tags (photo tags)
  72. (plist-put photo 'tags
  73. tags))
  74. (defun photogal--get-folders (photo)
  75. "What are all the folders for this file?"
  76. (plist-get photo 'folders))
  77. (defun photogal--set-folders (photo folders)
  78. (plist-put photo 'folders
  79. folders))
  80. (defun photogal--get-index (photo)
  81. (plist-get photo 'index))
  82. (defun photogal--set-index (photo index)
  83. (plist-put photo 'index
  84. index))
  85. (defun photogal--get-copy-to-dir? (photo)
  86. (plist-get photo 'copy-to-dir))
  87. (defun photogal--set-copy-to-dir? (photo copy-to-dir)
  88. (plist-put photo 'copy-to-dir
  89. copy-to-dir))
  90. ;; \\ // ;;
  91. (defun photogal-draw-buffer (photoreel buffer tags)
  92. (defun photogaldraw-index-tracker (photoreel)
  93. (let* ((current-file (photogal-current-file photoreel))
  94. (current-index (photogal--get-index current-file))
  95. (total-photos (length photoreel)))
  96. (insert " ur lookin at photo ")
  97. (photogal--insert-print-color current-index "red")
  98. (insert " of ")
  99. (photogal--insert-print-color total-photos "red")))
  100. (defun photogaldraw--commit-message (photo)
  101. (if (photogal--get-copy-to-dir? photo)
  102. (progn
  103. (insert "\t\t\t\t will commit?: ")
  104. (photogal--insert-print-color "✓" "SeaGreen3"))
  105. (progn
  106. (insert "\t\t\t\t will commit?: ")
  107. (photogal--insert-print-color "✗" "red"))))
  108. (defun photogaldraw--insert-image (filepath)
  109. (insert " ")
  110. (insert-image
  111. (if resize-image
  112. (create-image filepath 'imagemagick nil
  113. :width (- (window-pixel-width) 75))
  114. (create-image filepath 'imagemagick nil
  115. :height (/ (window-pixel-height) 2)))))
  116. (defun photogaldraw--newline ()
  117. (insert "\n"))
  118. (defun photogal--pprint-key-command (key-to-type name-of-command padding &optional activated)
  119. "Make the low-level insertions to the buffer to render a key-command."
  120. (let ((length-of-unit (+ (length key-to-type) (length name-of-command) 3)))
  121. (when (> (+ (+ (current-column) length-of-unit)
  122. 10)
  123. (window-width))
  124. (insert "\n"))
  125. (insert "[")
  126. (if activated
  127. (photogal--insert-print-color key-to-type "SeaGreen3")
  128. (photogal--insert-print-color key-to-type "dark gray"))
  129. (insert "] ")
  130. (photogal--insert-print-color name-of-command "blue" (- padding (length key-to-type)))
  131. (insert " ")))
  132. (defun photogaldraw--insert-tags (tags photo)
  133. (photogal--insert-print-color "Tag:\n" "red")
  134. (mapcar (lambda (tag)
  135. (let* ((key-command (photogal-tag-key tag))
  136. (tag-name (photogal-tag-name tag))
  137. (activated (photogal-file-has-tag? photo tag-name)))
  138. (photogal--pprint-key-command key-command tag-name 16 activated)))
  139. ;;(seq-sort (lambda (t1 t2) (string< (car t1) (car t2))) tags)
  140. tags
  141. )
  142. )
  143. (defun photogal--insert-print-color (string-to-insert-to-buffer color &optional padding)
  144. "Insert some text in this color."
  145. (let ((beg (point))
  146. (padding
  147. (if padding
  148. (format "%s" padding)
  149. "0")))
  150. (insert (format (concat "%-" padding "s") string-to-insert-to-buffer))
  151. (put-text-property beg (point) 'font-lock-face `(:foreground ,color))))
  152. (let* ((current-photo (photogal-current-file photoreel))
  153. (resize-image nil)
  154. (photo-file-path (photogal--get-filepath current-photo))
  155. (buf (get-buffer-create buffer)))
  156. (with-current-buffer buf
  157. (photogal-mode)
  158. (erase-buffer)
  159. (photogaldraw-index-tracker photoreel)
  160. (photogaldraw--commit-message current-photo)
  161. (photogaldraw--newline)
  162. (photogaldraw--insert-image (photogal--get-filepath current-photo))
  163. (photogaldraw--newline)
  164. (photogaldraw--insert-tags tags current-photo)
  165. (switch-to-buffer buf))
  166. )
  167. )
  168. (defun photogal-file-has-tag? (tag _) t)
  169. (defvar key-commands
  170. '(
  171. ;; ("G" . photogal-refresh-buffer)
  172. ;; ("RET" . photogal-next-file)
  173. ;; ("<right>" . photogal-next-file)
  174. ("SPC" . photogal-next-file)
  175. ;; ("C-p" . photogal-prev-file)
  176. ;; ("<left>" . photogal-prev-file)
  177. ;; ("C-a" . photogal-add-tag)
  178. ;; ("C-d" . photogal-delete-tag)
  179. ;; ("C-f" . photogal-show-filepath)
  180. ;; ("C-r" . photogal-resize-photo)
  181. ;; ("C-c" . photogal-compile-and-commit)
  182. ;; ("C-n" . photogal-name-the-file)
  183. ;; ("C-o" . photogal-give-a-folder)
  184. ))
  185. (defun photogal-next-file ()
  186. (interactive)
  187. (setq *photogal/photoreel* (photogal-advance-file *photogal/photoreel*))
  188. (photogal-render *photogal/photoreel*)
  189. )
  190. (defvar photogal-mode-map nil "Keymap for `photogal-mode`")
  191. (progn
  192. (setq photogal-mode-map (make-sparse-keymap))
  193. (map-do (lambda (key command)
  194. (eval `(define-key photogal-mode-map (kbd ,key) ',command)))
  195. key-commands))
  196. ;; // tag shit
  197. (defun photogal-all-parents (tags)
  198. (seq-filter (lambda (x) x)
  199. (seq-uniq (mapcar (lambda (tag) (plist-get (cdr tag) 'parent)) tags)
  200. (lambda (a b) (string= (car a) (car b))))))
  201. (defun photogal-tags-with-no-parents (tags)
  202. (seq-remove (lambda (tag) (plist-member (cdr tag) 'parent)) tags))
  203. (defun photogal-top-level-tags ()
  204. (append (photogal-all-parents *photogal/tags*)
  205. (photogal-tags-with-no-parents *photogal/tags*)))
  206. (defun photogal-tag-name (tag)
  207. (plist-get (cdr tag) 'name))
  208. (defun photogal-tag-key (tag)
  209. (car tag))