From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paul Sexton Subject: Active, fontified org hyperlinks in any major mode Date: Fri, 12 Mar 2010 00:27:45 +0000 (UTC) Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NpsjW-00045I-7n for emacs-orgmode@gnu.org; Thu, 11 Mar 2010 19:28:06 -0500 Received: from [140.186.70.92] (port=50527 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NpsjV-00043f-2E for emacs-orgmode@gnu.org; Thu, 11 Mar 2010 19:28:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NpsjT-00026y-4n for emacs-orgmode@gnu.org; Thu, 11 Mar 2010 19:28:04 -0500 Received: from lo.gmane.org ([80.91.229.12]:41340) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NpsjS-00026e-RF for emacs-orgmode@gnu.org; Thu, 11 Mar 2010 19:28:03 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1NpsjM-0005mG-VO for emacs-orgmode@gnu.org; Fri, 12 Mar 2010 01:27:59 +0100 Received: from rp.young.med.auckland.ac.nz ([130.216.140.20]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 12 Mar 2010 01:27:56 +0100 Received: from psexton by rp.young.med.auckland.ac.nz with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 12 Mar 2010 01:27:56 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org To activate and correctly fontify org [[hyperlinks]] in any major mode, add the following to your .emacs: (defun orgl-do-font-lock (add-or-remove) "Add or remove font-lock rules for org hyperlinks." (funcall add-or-remove nil '((org-activate-bracket-links (0 'org-link t))))) (defun orgl-enable () "Enable fontification of org-style hyperlinks in the current buffer." (interactive) ;; The following variable has to be bound to a string, or opening links ;; will not work. ;; There is probably a more elegant solution. (unless org-todo-line-tags-regexp (set (make-local-variable 'org-todo-line-tags-regexp) "DSFSFSFSF_UTTER_NONSENSE_TAG_SDSDFSFDF")) (orgl-do-font-lock 'font-lock-add-keywords) (font-lock-fontify-buffer)) (defun orgl-disable () "Disable fontification of org-style hyperlinks in the current buffer." (interactive) (remove-text-properties (point-min) (point-max) '(mouse-face t keymap t org-linked-text t invisible t intangible t org-no-flyspell t)) (orgl-do-font-lock 'font-lock-remove-keywords) (font-lock-fontify-buffer)) ;; Change lisp-mode-hook to whatever you want (add-hook 'lisp-mode-hook 'orgl-enable) I was amazed at how easy this was. The most obvious use for me is to put [[hyperlinks]] in source code comments. The link behaves the same as in org mode, i.e. by default it looks for a matching <>, then searches for the text of the link starting from the top of the buffer. Useful extensions would be: - Figure out how to force hiding of the [[ ... ]] brackets. They disappear only if the text is in the 'default' face. - Fontification of <> to make them stand out would be useful - Figure out how to define special link types outside org mode proper. eg in an emacs lisp file it would be good if the link [[defun:my-function]] would jump to a "(defun my-function ...." toplevel form. Paul