Skip to content

Instantly share code, notes, and snippets.

@syohex
Created November 19, 2011 02:59
Show Gist options
  • Save syohex/1378363 to your computer and use it in GitHub Desktop.
Save syohex/1378363 to your computer and use it in GitHub Desktop.
perldoc with anything in Emacs
;;
;; inspired and based on anything-vim-hacks
;;
(defconst perldoc-jp:buffer-name "*perldoc-jp*")
(defconst perldoc-jp-core:url "http://perldoc.jp/index/core")
(put 'perldoc-jp:exception-not-retrieved 'error-message "Perldoc jp - Not retrieved")
(put 'perldoc-jp:exception-not-retrieved 'error-conditions
'(perldoc-jp:exception-not-retrieved error))
(defun perldoc-jp:http-get ()
(ignore-errors (kill-buffer perldoc-jp:buffer-name))
(unless (eq 0 (call-process "curl" nil `(,perldoc-jp:buffer-name nil) nil
"-f"
"-X" "GET"
perldoc-jp-core:url))
(signal 'perldoc-jp:exception-not-retrieved "The requested URL returned error")))
(defun perldoc-jp:get-document (&optional buffer)
(cond
((stringp buffer) (setq buffer (get-buffer buffer)))
((null buffer) (setq buffer perldoc-jp:buffer-name)))
(save-current-buffer
(set-buffer buffer)
(goto-char (point-min))
(let (candidates-alist '())
(while (re-search-forward
"a +href=\"[^\"]+\">\\([^<]+\\)</a> +- +\\([^<]+\\)" nil t)
(let ((document (buffer-substring (match-beginning 1) (match-end 1)))
(explanation (buffer-substring (match-beginning 2) (match-end 2))))
(setq candidates-alist
(cons (cons (format "%-15s : %s" document explanation) document)
candidates-alist))))
(reverse candidates-alist))))
(perldoc-jp:http-get)
(setq perldoc-jp:test (perldoc-jp:get-document))
(defun perldoc-jp-core:anything ()
(interactive)
(perldoc-jp:http-get)
(anything
`((name . "Perl core document")
(candidates . perldoc-jp:get-document)
(action
("View Document" . (lambda (x)
(let ((manual-program "perldoc"))
(manual-entry x)))))
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment