Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 86 lines (80 sloc) 3.268 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
;;; org-link-minor-mode.el -- Enable org-mode links in non-org modes
;;
;; Copyright (C) 2012
;; Author: Sean O'Halpin <sean dot ohalpin at gmail dot com>
;;
;; Enables org-mode links of the form:
;;
;; http://www.bbc.co.uk
;; man:emacs
;; <http://www.bbc.co.uk>
;; [[http://www.bbc.co.uk][BBC]]
;; [[org-link-minor-mode]]
;; [2012-08-18]
;; <2012-08-18>
;;
;; Note that =org-toggle-link-display= will also work when this mode
;; is enabled.
;;

(require 'org)

(defun org-link-minor-mode-unfontify-region (beg end &optional maybe_loudly)
  "Remove fontification and activation overlays from links."
  (font-lock-default-unfontify-region beg end)
  (let* ((buffer-undo-list t)
         (inhibit-read-only t) (inhibit-point-motion-hooks t)
         (inhibit-modification-hooks t)
         deactivate-mark buffer-file-name buffer-file-truename)
    (org-decompose-region beg end)
    (remove-text-properties beg end
                            '(mouse-face t keymap t org-linked-text t
                                         invisible t intangible t
                                         help-echo t rear-nonsticky t
                                         org-no-flyspell t org-emphasis t))
    (org-remove-font-lock-display-properties beg end)))

;;;###autoload
(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-angle-links (0 'org-link t))
          '(org-activate-plain-links)
          '(org-activate-bracket-links (0 'org-link t))
          '(org-activate-dates (0 'org-date t))
          ))
        )
    (if org-link-minor-mode
        (if (derived-mode-p 'org-mode)
            (progn
              (message "org-mode doesn't need org-link-minor-mode")
              (org-link-minor-mode -1)
              )
          (font-lock-add-keywords nil org-link-minor-mode-keywords t)
          (kill-local-variable 'org-mouse-map)
          (org-set-local 'org-mouse-map
                         (let ((map (make-sparse-keymap)))
                           (define-key map [return] 'org-open-at-point)
                           (define-key map [tab] 'org-next-link)
                           (define-key map [backtab] 'org-previous-link)
                           (define-key map [mouse-2] 'org-open-at-point)
                           (define-key map [follow-link] 'mouse-face)
                           map)
                         )
          (org-set-local 'org-descriptive-links org-descriptive-links)
          (if org-descriptive-links (add-to-invisibility-spec '(org-link)))
          (org-set-local 'font-lock-unfontify-region-function
                         'org-link-minor-mode-unfontify-region)
          (org-restart-font-lock)
          )
      (unless (derived-mode-p 'org-mode)
        (font-lock-remove-keywords nil org-link-minor-mode-keywords)
        (org-restart-font-lock)
        (remove-from-invisibility-spec '(org-link))
        (kill-local-variable 'org-descriptive-links)
        (kill-local-variable 'org-mouse-map)
        (kill-local-variable 'font-lock-unfontify-region-function)
        )
      )
    )
  )

(provide 'org-link-minor-mode)
Something went wrong with that request. Please try again.