emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Paul Sexton <psexton@xnet.co.nz>
To: emacs-orgmode@gnu.org
Subject: Active, fontified org hyperlinks in any major mode
Date: Fri, 12 Mar 2010 00:27:45 +0000 (UTC)	[thread overview]
Message-ID: <loom.20100312T010227-82@post.gmane.org> (raw)

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 <<target>>, 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 <<targets>> 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

                 reply	other threads:[~2010-03-12  0:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20100312T010227-82@post.gmane.org \
    --to=psexton@xnet.co.nz \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).