* Patch: option to not hide brackets in org links
@ 2012-05-09 21:07 Paul Sexton
2012-05-10 7:31 ` Sean O'Halpin
0 siblings, 1 reply; 6+ messages in thread
From: Paul Sexton @ 2012-05-09 21:07 UTC (permalink / raw)
To: emacs-orgmode
I would like to be able to control whether the '[[' ...']]' brackets around
links are made invisible during fontification. The motivation is that I have a
minor mode that makes org-style links fully active and fontifed in other major
modes. But I can imagine some others might want to use it, as behaviour of
these invisible brackets is sometimes unpredictable at the end of lines --
sometimes the cursor appears outside the link, but pressing return actually
introduces a newline in the link.
The following is a patch to org.el that accomplishes this. It introduces a new
boolean global variable, defaulting to current behaviour.
--- dotemacs/site-lisp/org/lisp/org.el 2012-05-06 10:45:07.000000000 +1200
+++ org-new.el 2012-05-10 09:00:14.000000000 +1200
@@ -1383,6 +1383,17 @@
:group 'org-link
:type 'function)
+
+(defcustom org-hide-link-brackets-p
+ t
+ "Should the double square brackets [[...]] around links be invisible?
+Default is t."
+ :group 'org-link
+ :type 'boolean)
+
+(put 'org-hide-link-brackets-p 'safe-local-variable 'booleanp)
+
+
(defgroup org-link-store nil
"Options concerning storing links in Org-mode."
:tag "Org Store Link"
@@ -5576,9 +5587,10 @@
;; but that requires another match, protecting match data,
;; a lot of overhead for font-lock.
(ip (org-maybe-intangible
- (list 'invisible 'org-link
- 'keymap org-mouse-map 'mouse-face 'highlight
- 'font-lock-multiline t 'help-echo help)))
+ (append (list 'keymap org-mouse-map 'mouse-face 'highlight
+ 'font-lock-multiline t 'help-echo help)
+ (if org-hide-link-brackets-p
+ (list 'invisible 'org-link) nil))))
(vp (list 'keymap org-mouse-map 'mouse-face 'highlight
'font-lock-multiline t 'help-echo help)))
;; We need to remove the invisible property here. Table narrowing
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Patch: option to not hide brackets in org links
2012-05-09 21:07 Patch: option to not hide brackets in org links Paul Sexton
@ 2012-05-10 7:31 ` Sean O'Halpin
2012-05-10 8:56 ` Paul Sexton
0 siblings, 1 reply; 6+ messages in thread
From: Sean O'Halpin @ 2012-05-10 7:31 UTC (permalink / raw)
To: Paul Sexton; +Cc: emacs-orgmode
On Wed, May 9, 2012 at 10:07 PM, Paul Sexton <psexton.2a@gmail.com> wrote:
> I have a
> minor mode that makes org-style links fully active and fontifed in other major
> modes.
Is that publicly available anywhere?
Regards,
Sean
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Patch: option to not hide brackets in org links
2012-05-10 7:31 ` Sean O'Halpin
@ 2012-05-10 8:56 ` Paul Sexton
2012-05-13 1:41 ` Sean O'Halpin
0 siblings, 1 reply; 6+ messages in thread
From: Paul Sexton @ 2012-05-10 8:56 UTC (permalink / raw)
To: emacs-orgmode
Sean O'Halpin <sean.ohalpin <at> gmail.com> writes:
> Is that publicly available anywhere?
Here you go. To use, add orgl-enable to the relevant mode-hook, eg:
(add-hook 'python-mode-hook 'orgl-enable)
--------
(defface orgl-target-face
'((t (:foreground "cyan" :background "royalblue4" :weight normal)))
;; '((t (:weight bold :box (:line-width 1 :color "red"))))
"The face used to emphasise org-mode <<targets>>.")
(make-face 'orgl-target-face)
(setq orgl-target-face 'orgl-target-face)
(defvar *orgl-link-abbrevs*
'((lisp-mode ("defun" . "(defun %s (")
("class" . "(defclass %s (")
("wwdoc" . "file:../TODO::%s")))
"Define link abbreviations for each major mode.
The variable contains a list, each element of which has the
form (MAJOR-MODE (ABBREV . EXPANSION) .....)
ABBREV is a short string. Links of the form '[[ABBREV:TEXT]]' will
be expanded into EXPANSION. See the documentation for
org-link-abbrev-alist for more details.")
(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))))
(funcall add-or-remove nil `((,org-target-regexp (0 'orgl-target-face 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 following 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)
"XYZ_THIS@SHOULD_NEVER~MATCH_ZYX"))
(orgl-do-font-lock 'font-lock-add-keywords)
;; Stop org links from having invisible [[ brackets ]].
(remove-text-properties (point-min) (point-max) '(invisible nil))
(font-lock-fontify-buffer)
;; Add special link abbreviations.
(unless org-link-abbrev-alist-local
(make-local-variable 'org-link-abbrev-alist-local))
(dolist (pair (cdr (assoc major-mode *orgl-link-abbrevs*)))
(pushnew pair org-link-abbrev-alist-local)))
(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)
;; Remove special link abbreviations
(dolist (pair (cdr (assoc major-mode *orgl-link-abbrevs*)))
(setq org-link-abbrev-alist-local
(delete pair org-link-abbrev-alist-local))))
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Patch: option to not hide brackets in org links
2012-05-10 8:56 ` Paul Sexton
@ 2012-05-13 1:41 ` Sean O'Halpin
2012-05-13 23:43 ` Paul Sexton
0 siblings, 1 reply; 6+ messages in thread
From: Sean O'Halpin @ 2012-05-13 1:41 UTC (permalink / raw)
To: Paul Sexton; +Cc: emacs-orgmode
On Thu, May 10, 2012 at 9:56 AM, Paul Sexton <psexton.2a@gmail.com> wrote:
> Sean O'Halpin <sean.ohalpin <at> gmail.com> writes:
>> Is that publicly available anywhere?
>
> Here you go. To use, add orgl-enable to the relevant mode-hook, eg:
> (add-hook 'python-mode-hook 'orgl-enable)
>
[snip code]
Thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Patch: option to not hide brackets in org links
2012-05-13 1:41 ` Sean O'Halpin
@ 2012-05-13 23:43 ` Paul Sexton
2012-05-13 23:50 ` Samuel Wales
0 siblings, 1 reply; 6+ messages in thread
From: Paul Sexton @ 2012-05-13 23:43 UTC (permalink / raw)
To: emacs-orgmode
Sean O'Halpin <sean.ohalpin <at> gmail.com> writes:
> Thanks!
I just noticed that the main function, orgl-enable, sets the buffer's
modification status to true when it runs. This is because altering text
properties is considered a modification of the buffer.
Fixed by wrapping the offending line in a 'with-silent-modifications' macro.
Some older Emacsen may not have this macro -- alternative solutions
are given at:
http://stackoverflow.com/questions/2699857/emacs-how-to-intelligently-handle-
buffer-modified-when-setting-text-properties
(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 following 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)
"XYZ_THIS@SHOULD_NEVER~MATCH_ZYX"))
(orgl-do-font-lock 'font-lock-add-keywords)
;; Stop org links from having invisible [[ brackets ]].
(with-silent-modifications
(remove-text-properties (point-min) (point-max) '(invisible nil)))
(font-lock-fontify-buffer)
;; Add special link abbreviations.
(unless org-link-abbrev-alist-local
(make-local-variable 'org-link-abbrev-alist-local))
(dolist (pair (cdr (assoc major-mode *orgl-link-abbrevs*)))
(pushnew pair org-link-abbrev-alist-local)))
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Patch: option to not hide brackets in org links
2012-05-13 23:43 ` Paul Sexton
@ 2012-05-13 23:50 ` Samuel Wales
0 siblings, 0 replies; 6+ messages in thread
From: Samuel Wales @ 2012-05-13 23:50 UTC (permalink / raw)
To: Paul Sexton; +Cc: emacs-orgmode
NP in 22.
These changes fix warnings:
(defface orgl-target-face
'((t (:foreground "cyan" :background "royalblue4" :weight normal)))
;; '((t (:weight bold :box (:line-width 1 :color "red"))))
"The face used to emphasise org-mode <<targets>>."
:group 'orgl)
(make-face 'orgl-target-face)
(defvar orgl-target-face 'orgl-target-face)
--
The Kafka Pandemic: http://thekafkapandemic.blogspot.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-05-13 23:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-09 21:07 Patch: option to not hide brackets in org links Paul Sexton
2012-05-10 7:31 ` Sean O'Halpin
2012-05-10 8:56 ` Paul Sexton
2012-05-13 1:41 ` Sean O'Halpin
2012-05-13 23:43 ` Paul Sexton
2012-05-13 23:50 ` Samuel Wales
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).