Skip to content

Instantly share code, notes, and snippets.

@syohex
Created November 8, 2011 03:52
Show Gist options
  • Save syohex/1346952 to your computer and use it in GitHub Desktop.
Save syohex/1346952 to your computer and use it in GitHub Desktop.
cperl-perldocに補完機能をつけてみた
;; 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