From dfda58d720484124f9432a09d831a9d6292908af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6cker?= Date: Sat, 10 Apr 2010 12:46:45 +0200 Subject: [PATCH] org-open-file: match against dlink only if the command to be executed actually seems to use the subexpression matches as parameters. This does not try to determine if a subexpression match is actually used in the case of a custom lisp form. --- lisp/ChangeLog | 2 +- lisp/org.el | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index de18aedaf..49e411f17 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,6 +1,6 @@ 2010-04-10 Jan Böcker - * org.el (org-file-apps-entry-uses-grouping-p): new function. + * org.el (org-file-apps-entry-match-against-dlink-p): new function. (org-file-apps-ex): remove variable. (org-open-file): Integrate org-file-apps-ex functionality back into org-file-apps, and decide whether to match a regexp against diff --git a/lisp/org.el b/lisp/org.el index 671037004..73c07d2d7 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -9134,8 +9134,8 @@ If the file does not exist, an error is thrown." buffer-file-name (substitute-in-file-name (expand-file-name path)))) (file-apps (append org-file-apps (org-default-apps))) - (apps (remove-if 'org-file-apps-entry-uses-grouping-p file-apps)) - (apps-dlink (remove-if-not 'org-file-apps-entry-uses-grouping-p file-apps)) + (apps (remove-if 'org-file-apps-entry-match-against-dlink-p file-apps)) + (apps-dlink (remove-if-not 'org-file-apps-entry-match-against-dlink-p file-apps)) (remp (and (assq 'remote apps) (org-file-remote-p file))) (dirp (if remp nil (file-directory-p file))) (file (if (and dirp org-open-directory-means-index-dot-org) @@ -9243,14 +9243,23 @@ If the file does not exist, an error is thrown." (not (equal old-pos (point)))) (org-mark-ring-push old-pos old-buffer)))) -(defun org-file-apps-entry-uses-grouping-p (entry) +(defun org-file-apps-entry-match-against-dlink-p (entry) "This function returns non-nil if `entry' uses a regular - expression that has subexpressions, and which org-open-file - should therefore match against the whole link instead of the - filename." - (let ((selector (car entry))) + expression which should be matched against the whole link by + org-open-file. + + It assumes that is the case when the entry uses a regular + expression which has at least one grouping construct and the + action is either a lisp form or a command string containing + '%1', i.e. using at least one subexpression match as a + parameter." + (let ((selector (car entry)) + (action (cdr entry))) (if (stringp selector) - (> (regexp-opt-depth selector) 0) + (and (> (regexp-opt-depth selector) 0) + (or (and (stringp action) + (string-match "%1" action)) + (consp action))) nil))) (defun org-default-apps ()