org.el: Prevent link activation in source code blocks

* org.el (org-in-fixed-width-region-p): Save match data.
(org-in-src-block-p): Use case-folding for searching the block
boundaries.
(org-activate-plain-links, org-activate-angle-links)
(org-activate-bracket-links): Prevent link activation in
source code blocks.

Thanks to Sébastien Vauban for reporting a related issue.
This commit is contained in:
Bastien Guerry 2012-12-20 16:34:27 +01:00
parent e89994a75c
commit 8165be3aa5

View file

@ -5295,12 +5295,13 @@ will be prompted for."
"Run through the buffer and add overlays to links."
(catch 'exit
(let (f)
(when (re-search-forward (concat org-plain-link-re) limit t)
(when (and (re-search-forward (concat org-plain-link-re) limit t)
(not (org-in-src-block-p)))
(org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
(setq f (get-text-property (match-beginning 0) 'face))
(if (or (eq f 'org-tag)
(and (listp f) (memq 'org-tag f)))
nil
(unless (or (org-in-src-block-p)
(eq f 'org-tag)
(and (listp f) (memq 'org-tag f)))
(add-text-properties (match-beginning 0) (match-end 0)
(list 'mouse-face 'highlight
'face 'org-link
@ -5439,7 +5440,8 @@ by a #."
(defun org-activate-angle-links (limit)
"Run through the buffer and add overlays to links."
(if (re-search-forward org-angle-link-re limit t)
(if (and (re-search-forward org-angle-link-re limit t)
(not (org-in-src-block-p)))
(progn
(org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
(add-text-properties (match-beginning 0) (match-end 0)
@ -5467,7 +5469,8 @@ by a #."
(defun org-activate-bracket-links (limit)
"Run through the buffer and add overlays to bracketed links."
(if (re-search-forward org-bracket-link-regexp limit t)
(if (and (re-search-forward org-bracket-link-regexp limit t)
(not (org-in-src-block-p)))
(let* ((help (concat "LINK: "
(org-match-string-no-properties 1)))
;; FIXME: above we should remove the escapes.
@ -18958,7 +18961,8 @@ See the individual commands for more information."
(defsubst org-in-fixed-width-region-p ()
"Is point in a fixed-width region?"
(eq 'fixed-width (org-element-type (org-element-at-point))))
(save-match-data
(eq 'fixed-width (org-element-type (org-element-at-point)))))
(defun org-edit-special (&optional arg)
"Call a special editor for the stuff at point.
@ -20246,7 +20250,7 @@ and end of string."
"Whether point is in a code source block.
When INSIDE is non-nil, don't consider we are within a src block
when point is at #+BEGIN_SRC or #+END_SRC."
(let (ov)
(let ((case-fold-search t) ov)
(or (when (setq ov (overlays-at (point)))
(memq 'org-block-background
(overlay-properties
@ -20255,7 +20259,7 @@ when point is at #+BEGIN_SRC or #+END_SRC."
(save-match-data
(save-excursion
(move-beginning-of-line 1)
(looking-at ".*#\\+\\(BEGIN\\|END\\)_SRC")))))))
(looking-at ".*#\\+\\(begin\\|end\\)_src")))))))
(defun org-context ()
"Return a list of contexts of the current cursor position.