;; 2010-06-07 ;; ∑ http://xahlee.org/ (defun emacs-ref-linkify () "Make the current line or selection into a emacs reference link. For example, if the cursor is any one of the line: (elisp) The Mark file:///Users/xah/web/xahlee_org/emacs_manual/elisp/The-Mark.html#The-Mark file:///Users/xah/web/xahlee_org/emacs_manual/elisp/The-Mark.html http://xahlee.org/emacs_manual/elisp/The-Mark.html ~/web/xahlee_org/emacs_manual/elisp/The-Mark.html c:/Users/xah/web/xahlee_org/emacs_manual/elisp/The-Mark.html ../emacs_manual/elisp/The-Mark.html Then it'll become: (info \"(elisp) The Mark\")" (interactive) (let (bds p1 p2 ξinput ξinfoStr linkText ξrpath ; relative path ) (setq bds (get-selection-or-unit 'line)) (setq ξinput (elt bds 0) ) (setq p1 (elt bds 1) ) (setq p2 (elt bds 2) ) ;; remove white spaces in beginning and ending (setq ξinput (trim-string ξinput)) ;; generate ξinfoStr. A info string is like this: “(elisp) The Mark” (setq ξinfoStr (if (or (string-match "(emacs)" ξinput) (string-match "(elisp)" ξinput) ) (setq ξinfoStr ξinput) (let (ξfpath ξtemp) ;; convert local URL to file path (setq ξfpath (cond ((string-match "^file" ξinput) (local-url-to-file-path ξinput)) ((string-match "^http" ξinput) (xahsite-url-to-filepath ξinput)) (t ξinput) ) ) ;; convert file path to info node syntax (concat (cond ((string-match "emacs_manual/elisp" ξfpath ) "(elisp) ") ((string-match "emacs_manual/emacs" ξfpath ) "(emacs) ") (t (error "ξfpath doesn't match “elisp” or “emacs”: %s" ξfpath)) ) (replace-regexp-in-string "_002d" "-" (replace-regexp-in-string "-" " " (file-name-sans-extension (file-name-nondirectory ξfpath)))) ) ) ) ) ;; generate link text (setq linkText (concat "(info \"" ξinfoStr "\")")) ;; generate relative file path (setq ξrpath ξinfoStr) (setq ξrpath (replace-regexp-in-string "(elisp) " "" ξrpath)) (setq ξrpath (replace-regexp-in-string "(emacs) " "" ξrpath)) (setq ξrpath (replace-regexp-in-string "-" "_002d" ξrpath)) (setq ξrpath (replace-regexp-in-string " " "-" ξrpath)) (cond ((string-match "(elisp)" ξinfoStr ) (setq ξrpath (concat "../emacs_manual/elisp/" ξrpath ".html"))) ((string-match "(emacs)" ξinfoStr ) (setq ξrpath (concat "../emacs_manual/emacs/" ξrpath ".html"))) (t (error "ξinfoStr doesn't match “(elisp)” or “(emacs)”: %s" ξinfoStr)) ) (if (file-exists-p ξrpath) (progn (delete-region p1 p2) (insert "" linkText "")) (error "Generated local ξrpath “%s” does not point to a file" ξrpath))) ) (defun php-ref-linkify () "Make the current line into a PHP reference link. If there's a text selection, use that. For example, if the cursor is on the word: echo Then it'll become echo" (interactive) (let (bds p1 p2 swd ξurl) (setq bds (get-selection-or-unit 'glyphs)) (setq swd (elt bds 0) ) (setq p1 (elt bds 1) ) (setq p2 (elt bds 2) ) (setq ξurl (concat "http://us.php.net/" swd) ) (delete-region p1 p2) (insert "" swd ""))) (defun java-ref-linkify () "Make the current line into a Java reference link. If there's a text selection, use that. For example, if the cursor is on the line: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html Then it'll become Java Doc: String The input string can be the URL to the official Java API, Java Language Spec, the Java Tutorial." (interactive) (let (bds p1 p2 ξurl kword) (setq bds (get-selection-or-unit 'glyphs)) (setq ξurl (elt bds 0) ) (setq p1 (elt bds 1) ) (setq p2 (elt bds 2) ) (setq kword (file-name-sans-extension (file-name-nondirectory ξurl))) (delete-region p1 p2) (cond ((string-match "j2se/1.5" ξurl) (insert "Java Doc: " kword "")) ((string-match "tutorial" ξurl) (insert "Java Tutorial: " kword "")) ((string-match "jls" ξurl) (insert "Java Lang Spec: " kword ""))))) (defun perldoc-ref-linkify () "Make the current line into a link to Perl's doc site. For example, if the cursor is on the line: perlop Then it'll become perldoc perlop" (interactive) (let (bds p1 p2 swd ξurl) (setq bds (get-selection-or-unit 'glyphs)) (setq swd (elt bds 0) ) (setq p1 (elt bds 1) ) (setq p2 (elt bds 2) ) (setq ξurl (concat "http://perldoc.perl.org/" swd ".html") ) (setq ξurl (replace-regexp-in-string "::" "/" ξurl )) (setq ξurl (replace-regexp-in-string "-f " "functions/" ξurl )) (delete-region p1 p2) (insert "" "perldoc " swd ""))) (defun mathematica-ref-linkify () "Make the current line into a link to Mathematica ref site. If there's a text selection, use that. For example, if the cursor is on the line: Table Then it'll become: Mathematica Ref: Table" (interactive) (let (bds p1 p2 swd ξurl) (setq bds (get-selection-or-unit 'glyphs)) (setq swd (elt bds 0) ) (setq p1 (elt bds 1) ) (setq p2 (elt bds 2) ) (setq ξurl (concat "http://reference.wolfram.com/mathematica/ref/" swd ".html") ) (delete-region p1 p2) (insert "" "Mathematica: " swd "")))