Skip to content
Browse files

On exit from mode, remove more of the fontification added

  • Loading branch information...
1 parent c128e59 commit e660ed02c7af433a961b104152a5f487b9900d07 @seanohalpin committed Aug 25, 2012
Showing with 58 additions and 4 deletions.
  1. +18 −1 org-link-minor-mode.el
  2. +40 −3 org-link-minor-mode.org
View
19 org-link-minor-mode.el
@@ -19,6 +19,22 @@
(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
+ fontified t
+ org-no-flyspell t org-emphasis t))
+ (org-remove-font-lock-display-properties beg end)))
+
(define-minor-mode org-link-minor-mode
"Toggle display of org-mode style bracket links in non-org-mode buffers."
:lighter " org-link"
@@ -51,12 +67,13 @@
(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-unfontify-region)
+ '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)
43 org-link-minor-mode.org
@@ -1,5 +1,7 @@
-#+TITLE: org-link-minor-mode
#+SETUPFILE: ~/org/setup2.org
+#+TITLE: org-link-minor-mode
+#+AUTHOR: Sean O'Halpin
+#+DATE: 2012-08-25
#+PROPERTY: eval never
#+COMMENT: comments noweb
#+LINK: elisp http://www.gnu.org/software/emacs/manual/html_node/elisp/%s.html
@@ -98,7 +100,7 @@ the mode:
If we're already in org-mode, display a message and
switch =org-link-minor-mode= off. We need to do it this way as by this
-point we've already entered the mode.
+point we've already entered the minor mode (=org-link-minor-mode= == t):
#+name: enter-minor-mode
#+begin_src emacs-lisp :noweb tangle
@@ -155,9 +157,13 @@ into it (or use replace to make it no longer a link):
#+begin_src emacs-lisp
(org-set-local 'font-lock-unfontify-region-function
- 'org-unfontify-region)
+ 'org-link-minor-mode-unfontify-region)
#+end_src
+The [[elisp:Search_002dbased-Fontification][documentation]] for [[elisp:Other-Font-Lock-Variables][=font-lock-unfontify-region-function=]] is a bit
+sparse but reading =org-unfontify-region= at least shows you what it
+should do.
+
Finally, we refontify the buffer using org's own method:
#+begin_src emacs-lisp
@@ -194,11 +200,40 @@ Restore existing font lock highlighting
#+begin_src emacs-lisp
(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)
#+end_src
+* Remove text properties
+
+=org-unfontify-region= does not remove the =help-echo= and =rear-nonsticky=
+properties, so I've copied the function and added those in.
+
+Actually, this looks like a bug in =org-unfontify-region=.
+
+(Note: should I be removing the =fontified= property too? It doesn't
+look like other modes do this.)
+
+#+name: org-link-minor-mode-unfontify-region
+#+begin_src emacs-lisp
+ (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)))
+#+end_src
+
* Provide
:PROPERTIES:
:ID: 317688ba-da16-4a42-9e4f-20b06a8d86cf
@@ -222,6 +257,8 @@ Here is the complete source:
<<requires>>
+<<org-link-minor-mode-unfontify-region>>
+
<<define-minor-mode>>
<<provide>>

0 comments on commit e660ed0

Please sign in to comment.
Something went wrong with that request. Please try again.