Hi,

I've been hacking this weekend to try to create a minor mode that
enables org-mode bracket links in modes other than org-mode.

I believe this has been mooted before
(e.g. http://lists.gnu.org/archive/html/emacs-orgmode/2009-08/msg00573.html).

The following codes works for me but I'm sure it could be improved.

I'm an elisp noob so I'd very much appreciate feedback on the approach
I'm taking.  For example, I'm not sure how to prevent turning on
org-link-minor-mode from an org-mode buffer - advice would be welcome.

Regards,
Sean

#+begin_src emacs-lisp

(require 'org)

(define-minor-mode org-link-minor-mode
  "Toggle display of org-mode style bracket links in non-org-mode buffers."
  :lighter " org-link"
  (let ((org-link-minor-mode-keywords (list
'(org-activate-bracket-links (0 'org-link t)))))
    (save-excursion
      (save-match-data
        (goto-char (point-min))
        (if org-link-minor-mode
            (progn
              (font-lock-add-keywords nil org-link-minor-mode-keywords t)
              (set (make-local-variable 'org-descriptive-links)
org-descriptive-links)
              (if org-descriptive-links (add-to-invisibility-spec '(org-link)))
              (font-lock-fontify-buffer)
              )
          (progn
            (font-lock-remove-keywords nil org-link-minor-mode-keywords)
            (org-remove-from-invisibility-spec '(org-link))
            (while (re-search-forward org-bracket-link-regexp nil t)
              ;; Remove all org-link properties
              (remove-text-properties (match-beginning 0) (match-end
0) (text-properties-at (match-beginning 0)))
              )
            )
          )))))

(provide 'org-link-minor-mode)

#+end_src

Reply via email to