From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: radio links in middle of words. Date: Thu, 10 Apr 2014 23:43:41 +0200 Message-ID: <87k3awkghe.fsf@gmail.com> References: <878urp64ou.wl%n142857@gmail.com> <87bnwjopj5.fsf@gmail.com> <8738hv65n6.wl%n142857@gmail.com> <87sipvwtxy.fsf@gmail.com> <87r45d41fk.wl%n142857@gmail.com> <878urk9b07.fsf@gmail.com> <87ob09pdc9.wl%n142857@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYMkh-0002Gn-LY for emacs-orgmode@gnu.org; Thu, 10 Apr 2014 17:43:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WYMkc-0000gl-Mw for emacs-orgmode@gnu.org; Thu, 10 Apr 2014 17:43:19 -0400 Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]:59190) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYMkc-0000gf-BB for emacs-orgmode@gnu.org; Thu, 10 Apr 2014 17:43:14 -0400 Received: by mail-wi0-f181.google.com with SMTP id hm4so65737wib.2 for ; Thu, 10 Apr 2014 14:43:13 -0700 (PDT) In-Reply-To: <87ob09pdc9.wl%n142857@gmail.com> (Daniel Clemente's message of "Thu, 10 Apr 2014 19:40:22 +0700") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Daniel Clemente Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, Daniel Clemente writes: > I propose: radio links should be delimited by characters that don't mat= ch [:alpha:] in emacs' regular expression syntax. > Letters (like: a=C3=A1=E6=9B=B8=C4=89) match, and delimiters (like: -'"= /) don't. > > Test it with: > : (string-match-p "[[:alpha:]]" "=C3=A1") > : (string-match-p "[[:alpha:]]" "=E6=9B=B8") > : (string-match-p "[[:alpha:]]" "=C4=89") > > : (string-match-p "[[:alpha:]]" "'") > : (string-match-p "[[:alpha:]]" "-") > > And the opposite: check for non-letterness: > : (string-match-p "[^[:alpha:]]" "-") > : (string-match-p "[^[:alpha:]]" "=C3=A1") > > > So a radio link with LINK_TEXT should not only be a match of the > regexp "LINK_TEXT" but of "[^[:alpha:]]LINK_TEXT[^[:alpha:]]" (well, > make it something like "(^|non-letter)LINK_TEXT($|non-text)". > > I think that's better than the current solution and stills allows > for radio links which contain non-letters, like <<>>. What > do you think? It could work. But I think [:alnum:] is needed instead of [:alpha:]. Here's a patch implementing it. Regards, --=20 Nicolas Goaziou --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-No-alphanumeric-characters-around-radio-links.patch >From 581e68fda98e737043fce479e6eb0cf2b3599c9b Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 10 Apr 2014 22:23:27 +0200 Subject: [PATCH] No alphanumeric characters around radio links * lisp/org.el (org-make-target-link-regexp): Change regexp so alphanumeric characters cannot be found next to a radio link. (org-activate-target-links): Apply changes to radio link regexp. * lisp/org-element.el (org-element--object-lex, org-element-link-parser): Apply changes to radio link regexp. * testing/lisp/test-org-element.el (test-org-element/link-parser): Update test. Patch suggested by Daniel Clemente. http://permalink.gmane.org/gmane.emacs.orgmode/84461 --- lisp/org-element.el | 15 +++++++++------ lisp/org.el | 10 +++++----- testing/lisp/test-org-element.el | 7 +++---- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 06cce47..13837e9 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -2943,12 +2943,14 @@ Assume point is at the beginning of the link." raw-link link search-option application) (cond ;; Type 1: Text targeted from a radio target. - ((and org-target-link-regexp (looking-at org-target-link-regexp)) + ((and org-target-link-regexp + (save-excursion (or (bolp) (backward-char)) + (looking-at org-target-link-regexp))) (setq type "radio" - link-end (match-end 0) - path (org-match-string-no-properties 0) - contents-begin (match-beginning 0) - contents-end (match-end 0))) + link-end (match-end 1) + path (org-match-string-no-properties 1) + contents-begin (match-beginning 1) + contents-end (match-end 1))) ;; Type 2: Standard link, i.e. [[http://orgmode.org][homepage]] ((looking-at org-bracket-link-regexp) (setq contents-begin (match-beginning 3) @@ -4184,8 +4186,9 @@ to an appropriate container (e.g., a paragraph)." (save-excursion (let ((limit (and org-target-link-regexp (save-excursion + (or (bolp) (backward-char)) (re-search-forward org-target-link-regexp nil t)) - (match-beginning 0))) + (match-beginning 1))) found) (while (and (not found) (re-search-forward org-element--object-regexp limit t)) diff --git a/lisp/org.el b/lisp/org.el index aa86a3c..321eb71 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -6091,13 +6091,13 @@ by a #." (let ((case-fold-search t)) (if (re-search-forward org-target-link-regexp limit t) (progn - (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0)) - (add-text-properties (match-beginning 0) (match-end 0) + (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1)) + (add-text-properties (match-beginning 1) (match-end 1) (list 'mouse-face 'highlight 'keymap org-mouse-map 'help-echo "Radio target link" 'org-linked-text t)) - (org-rear-nonsticky-at (match-end 0)) + (org-rear-nonsticky-at (match-end 1)) t))))) (defun org-update-radio-target-regexp () @@ -6192,13 +6192,13 @@ targets." The regular expression finds the targets also if there is a line break between words." (and targets - (concat "\\(" + (concat "\\(?:^\\|[^[:alnum:]]\\)\\(" (mapconcat (lambda (x) (replace-regexp-in-string " +" "\\s-+" (regexp-quote x) t t)) targets "\\|") - "\\)"))) + "\\)\\(?:$\\|[^[:alnum:]]\\)"))) (defun org-activate-tags (limit) (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \r\n]") limit t) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 4eccb69..0f81a79 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -1336,12 +1336,11 @@ e^{i\\pi}+1=0 (should (equal "radio" - (org-test-with-temp-text "A radio link" + (org-test-with-temp-text "<<>>A radio link" + (org-update-radio-target-regexp) (org-element-property :type - (org-element-map - (let ((org-target-link-regexp "radio")) (org-element-parse-buffer)) - 'link 'identity nil t))))) + (org-element-map (org-element-parse-buffer) 'link #'identity nil t))))) ;; Standard link. ;; ;; ... with description. -- 1.9.2 --=-=-=--