Sep 8, 2014 • Michael Chen

Sometimes we want to browse online document for the usages of Perl subroutines or modules. It is boringly repetitive to open the browser and key in the keywords. Is there any way to automate the process? With some tricks, you can open online documents by hotkeys.

You may check this original Emacs script to utilize p3rl.org. p3rl.org is a web service providing shortened url for online Perl documents and Perl module documents. By using the service, you may access Perl online documents and Perl module documents with the same url. Here we provide this tip to directly access Perl documents from Emacs.

Check that whether thing-at-point is available in your Emacs before start the hack. thing-at-point is a built-in part of Emacs, so it should already be available. One way to check its existence is using M-x find-library RET thingatpt within Emacs. If not, install it.

Add all the following contents in ~/.emacs. First, register a new key word bounds at point.

;; extend thing-at-point to match a Perl subroutine or module
(defun perl-module-bounds-of-perl-module-at-point ()
  "Return the start and end point of a Perl module"
    (if (looking-at "[A-Za-z0-9:]+")
	(cons (point) (match-end 0))

;; register to thing-at-point
(put 'perl-module 'bounds-of-thing-at-point

Next, set the command to browse the url from Emacs.

;; set http://p3rl.org string
(defcustom perl-search-url "http://p3rl.org/"
  "URL at which to search for documentation on a word"
  :type 'string
  :group 'perl)

;; browse document with browse-url command
(defun perl-search-documentation ()
  "Search Perl documentation for the word at the point."
  (browse-url (concat perl-search-url (thing-at-point 'perl-module))))

;; set hotkey, you may change to other hotkey
(global-set-key "\C-c\C-f"  'perl-search-documentation)

Then, we can browse online Perl documents for subroutine and modules at the location of these keywords with C-c C-f, saving many repetitive keystrokes.