Created
November 8, 2011 03:52
-
-
Save syohex/1346952 to your computer and use it in GitHub Desktop.
cperl-perldocに補完機能をつけてみた
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; IMAKADOさんの plcmp-cmd-show-docの方がすごいのでそちらを使うべき。 | |
(defun cperl-perldoc+ () | |
(interactive) | |
(let* ((imported-module-alist '()) | |
(word-at-point (cperl-word-at-point)) | |
(word-at-point-str (if word-at-point | |
(substring-no-properties word-at-point))) | |
(module-regex "\\(use\\|require\\)\\s +\\([^ ;]+\\)")) | |
(save-excursion | |
(goto-char (point-min)) | |
(while (re-search-forward module-regex nil t) | |
(setq imported-module-alist | |
(cons (list (buffer-substring-no-properties | |
(match-beginning 2) (match-end 2))) | |
imported-module-alist))) | |
(let* ((manual-program "perldoc") | |
(default-value | |
(if word-at-point-str | |
(let ((longest 0) longest-matched) | |
(dolist (module imported-module-alist longest-matched) | |
(let ((name (car module)) | |
(len (length (car module)))) | |
(if (and (string-match name word-at-point) | |
(> len longest)) | |
(setq longest len longest-matched name))))))) | |
(prompt (format "perldoc entry %s: " | |
(if default-value | |
(format "(default %s)" default-value) | |
""))) | |
(input (completing-read prompt imported-module-alist))) | |
(manual-entry (cond | |
((and input (not (string= input ""))) input) | |
(default-value default-value) | |
(t (error "no input")))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment