restored man wrapper functions into the new lisp directory

master
John Turner 2 years ago
parent c284f5b2c4
commit fa40958eae
No known key found for this signature in database
GPG Key ID: 8CC352A6103A8DF6

@ -0,0 +1,36 @@
(defun man-wrapper-find-pages ()
(let* ((manpath (getenv "MANPATH"))
(directories (split-string manpath ":" t))
(that-exist (seq-filter 'file-exists-p directories))
(files (mapcar (lambda (d)
(directory-files-recursively d ".*" nil))
that-exist))
(flattened (flatten-list files))
(pages (mapcar 'file-name-nondirectory flattened))
(without-second-ext (mapcar (lambda (p)
(let ((extension (file-name-extension p)))
(if (string-match-p "^[0-9+]$" extension)
p
(file-name-sans-extension p))))
pages)))
without-second-ext))
(defun man-wrapper-locate-page (page)
(with-temp-buffer
(let ((exit-code (call-process "man" nil (current-buffer) nil "--where" page)))
(when exit-code
(let* ((output (buffer-string))
(trimmed (string-trim-right output "\n")))
trimmed)))))
(defun man-wrapper (orig &rest args)
(interactive)
(let* ((arg (if args
(nth 0 args)
(completing-read "Select page: " (man-wrapper-find-pages))))
(page (man-wrapper-locate-page arg)))
(funcall orig page)))
(advice-add 'man :around 'man-wrapper)
(provide 'man-wrapper)

@ -1,4 +1,7 @@
(let ((local-lisp-directory (file-name-concat user-emacs-directory "lisp"))) (let ((local-lisp-directory (file-name-concat user-emacs-directory "lisp")))
(add-to-list 'load-path (file-name-concat local-lisp-directory "backup-before-save"))) (add-to-list 'load-path (file-name-concat local-lisp-directory "backup-before-save"))
(add-to-list 'load-path (file-name-concat local-lisp-directory "man-wrapper")))
(require 'backup-before-save) (require 'backup-before-save)
(require 'man-wrapper)

Loading…
Cancel
Save