summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--eshell-conf.el65
1 files changed, 65 insertions, 0 deletions
diff --git a/eshell-conf.el b/eshell-conf.el
index 0884d49..f77f5d3 100644
--- a/eshell-conf.el
+++ b/eshell-conf.el
@@ -723,6 +723,8 @@ For example, \"...\" expands into \"../..\"."
;; It is convenient to be able to compile multiple GraphViz files or
;; delete multiple image files simultaneously.
+;;;; A convenient Command
+
(require 'vc)
(defun eshell/gv (&rest args)
@@ -849,5 +851,68 @@ The file names should not include any extension."
args))))
nil)
+;;;; Completion
+
+(defun gv-complete-switches ()
+ "Return a completion table for the switches of the gv command."
+ (pcomplete-from-help
+ (list
+ "emacs" "-Q" "-l" "~/.emacs.d/eshell-conf.el" "--batch" "--eval" "(eshell/gv)")
+ :narrow-end "mapbacktrace"
+ :narrow-start "extension."))
+
+(defun gv-complete-files (dir)
+ "Return a completion table for the file arguments of the gv \
+command."
+ (lambda (string pred action)
+ (let ((default-directory (expand-file-name "output" dir))
+ (pred (lambda (name) (string-suffix-p ".gv" name)))
+ (filter (lambda (result)
+ (cond
+ ((string-suffix-p ".gv" result)
+ (substring result 0 -3))
+ (result)))))
+ (cond
+ ((eq action t)
+ (let ((results
+ (completion-table-with-predicate
+ #'completion-file-name-table
+ pred 'strict string pred action)))
+ (mapcar filter results)))
+ ((null action)
+ (funcall filter (completion-table-with-predicate
+ #'completion-file-name-table
+ pred 'strict string pred action)))
+ ((completion-table-with-predicate
+ #'completion-file-name-table
+ pred 'strict string pred action))))))
+
+(defun pcomplete/gv ()
+ "Completion for `eshell/gv'."
+ (let (finding-dir continue-loop)
+ (while (or (string-prefix-p "-" (pcomplete-arg)) continue-loop)
+ (let ((arg (pcomplete-arg)))
+ (pcomplete-here (cond
+ ((eq finding-dir t) (pcomplete-dirs))
+ (continue-loop
+ (list "png" "jpeg" "jpg" "svg"))
+ ((gv-complete-switches))))
+ (cond
+ ((eq finding-dir t)
+ (setq finding-dir arg)
+ (setq continue-loop nil))
+ (continue-loop (setq continue-loop nil))
+ ((string-prefix-p "-d" arg)
+ (setq finding-dir
+ (cond
+ ((string= arg "-d") (setq continue-loop t))
+ ((substring-no-properties arg 2)))))
+ ((string= "--format" arg)
+ (setq continue-loop t))
+ ((string= "--root" arg)
+ (setq finding-dir (setq continue-loop t)))
+ ((setq continue-loop nil)))))
+ (while (pcomplete-here (gv-complete-files finding-dir)))))
+
(provide 'eshell-conf)
;;; eshell-conf.el ends here