Parcourir la source

commands are like C-{_}

jordyn il y a 2 ans
Parent
commit
1069f4ab0d
1 fichiers modifiés avec 36 ajouts et 28 suppressions
  1. 36 28
      photogal.el

+ 36 - 28
photogal.el

@@ -26,17 +26,7 @@
 (defvar *photogal/operating-table* nil)
 (defvar *photogal/--resize-photo* nil)
 (defvar *photogal/photos-origin-directory* nil)
-(defvar *photogal/commands*
-  '(("RET" . "Next")
-    ("P" . "Prev")
-    ("A" . "Add tag")
-    ("D" . "Delete tag")
-    ("F" . "Show filename")
-    ("G" . "Refresh buffer")
-    ("R" . "Resize photo")
-    ("C" . "Commit all")
-    ("N" . "Name the file")
-    ("O" . "Add a dir")))
+
 
 (defcustom photogal-default-directory "/Users/jwd/bench/photos/"
   "This is where photogal will look for photos.")
@@ -56,6 +46,18 @@
     ("s" . "selfie"))
     "Tags and key-command to associate to photos.")
 
+(defvar *photogal/commands*
+  '(("RET" . "Next")
+    ("C-p" . "Prev")
+    ("C-a" . "Add tag")
+    ("C-d" . "Delete tag")
+    ("C-f" . "Show filename")
+    ("C-g" . "Refresh buffer")
+    ("C-r" . "Resize photo")
+    ("C-c" . "Commit all")
+    ("C-n" . "Name the file")
+    ("C-o" . "Add a dir")))
+
 (defun photogal-get-tags-for-file (photo-filepath)
   "what tags does this file have?"
   (photogal--get-tags (photogal--lookup-photo photo-filepath)))
@@ -401,7 +403,7 @@ for all tags defined -- one function per tag."
 	    (let* ((key-command (car tag))
 		   (tag-name (cdr tag))
 		   (activated (photogal-file-has-tag? (photogal-current-file) tag-name)))
-	      (photogal--pprint-key-command key-command tag-name activated)))
+	      (photogal--pprint-key-command key-command tag-name 16 activated)))
 	  (seq-sort (lambda (t1 t2) (string< (car t1) (car t2))) tags)))
 
 (defun photogal-insert-commands-to-buffer (commands)
@@ -409,10 +411,10 @@ for all tags defined -- one function per tag."
   (mapcar (lambda (command)
 	    (let ((key-command (car command))
 		  (command-name (cdr command)))
-	      (photogal--pprint-key-command key-command command-name)))
+	      (photogal--pprint-key-command key-command command-name 24)))
 	  commands))
 
-(defun photogal--pprint-key-command (key-to-type name-of-command &optional activated)
+(defun photogal--pprint-key-command (key-to-type name-of-command padding &optional activated)
   "Make the low-level insertions to the buffer to render a key-command."
   (let ((length-of-unit (+ (length key-to-type) (length name-of-command) 3)))
     (when (> (+ (+ (current-column) length-of-unit)
@@ -424,7 +426,7 @@ for all tags defined -- one function per tag."
 	(photogal--insert-print-color key-to-type "SeaGreen3")
       (photogal--insert-print-color key-to-type "dark gray"))
     (insert "] ")
-    (photogal--insert-print-color name-of-command "blue" (- 16 (length key-to-type)))
+    (photogal--insert-print-color name-of-command "blue" (- padding (length key-to-type)))
     (insert " ")))
 
 (defun photogal--insert-print-color (string-to-insert-to-buffer color &optional padding)
@@ -519,21 +521,27 @@ the current file."
 
 (defvar photogal-mode-map nil "Keymap for `photogal-mode`")
 
+(defvar key-commands
+  '(("G" . photogal-refresh-buffer)
+    ("RET" . photogal-next-file)
+    ("<right>" . photogal-next-file)
+    ("SPC" . photogal-next-file)
+    ("C-p" . photogal-prev-file)
+    ("<left>" . photogal-prev-file)
+    ("C-a" . photogal-add-tag)
+    ("C-d" . photogal-delete-tag)
+    ("C-f" . photogal-show-filepath)
+    ("C-r" . photogal-resize-photo)
+    ("C-c" . photogal-compile-and-commit)
+    ("C-n" . photogal-name-the-file)
+    ("C-o" . photogal-give-a-folder)))
+
+
 (progn
   (setq photogal-mode-map (make-sparse-keymap))
-  (define-key photogal-mode-map (kbd "G") 'photogal-refresh-buffer)
-  (define-key photogal-mode-map (kbd "RET") 'photogal-next-file)
-  (define-key photogal-mode-map (kbd "<right>") 'photogal-next-file)
-  (define-key photogal-mode-map (kbd "SPC") 'photogal-next-file)
-  (define-key photogal-mode-map (kbd "P") 'photogal-prev-file)
-  (define-key photogal-mode-map (kbd "<left>") 'photogal-prev-file)
-  (define-key photogal-mode-map (kbd "A") 'photogal-add-tag)
-  (define-key photogal-mode-map (kbd "D") 'photogal-delete-tag)
-  (define-key photogal-mode-map (kbd "F") 'photogal-show-filepath)
-  (define-key photogal-mode-map (kbd "R") 'photogal-resize-photo)
-  (define-key photogal-mode-map (kbd "C") 'photogal-compile-and-commit)
-  (define-key photogal-mode-map (kbd "N") 'photogal-name-the-file)
-  (define-key photogal-mode-map (kbd "O") 'photogal-give-a-folder))
+  (map-do (lambda (key command)
+	    (eval `(define-key photogal-mode-map (kbd ,key) ',command)))
+	  key-commands))
 
 (define-derived-mode photogal-mode text-mode "photogal"
   "Major mode for grouping and labeling images.")