diff options
author | JSDurand <mmemmew@gmail.com> | 2023-02-26 14:20:24 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2023-02-26 14:20:24 +0800 |
commit | 03a07cd49cf2cd8ba51e855347c0e175f86934c9 (patch) | |
tree | 1fcd279b05412ddca689e5dbd53960c834d2c83e | |
parent | f0e6ac0875a67b5b7acae8d5a998c58f6899a658 (diff) |
eshell: Add completion support for the gv command
* eshell-conf.el (pcomplete/gv): This function will be called by
pcomplete to provide completions for the gv command, in Eshell.
(gv-complete-switches): This function provides completions for the
switches of the gv command.
(gv-complete-files): This function provides completions for source
files that are valid for the gv command.
-rw-r--r-- | eshell-conf.el | 65 |
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 |