emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* one line fix for org-publish-get-project-from-filename when filename has regexp chars in it
@ 2012-05-14  2:27 Neil Smithline
  0 siblings, 0 replies; only message in thread
From: Neil Smithline @ 2012-05-14  2:27 UTC (permalink / raw)
  To: Org Mode

Found a bug when a project's base directory has regexp characters in it. 
This probably happens often for `.' but nobody cares because that likely 
returns the correct result. But I had a `+' in my project's base 
directory name.

I've included the revised function below with my change "subtly" marked by:
        !!!!!HERE!!!!

This being my first time creating an org project, I kept thinking it was 
something with my project config. Finally I decided it was a bug as I 
got a test project to work.

In order to file a coherent bug report, I tried to narrow the bug down 
to an easy test case. It was when I got it down to a bug in 
`string-match' that I started to think there might be another problem.

It still took me some trial and error with the filenames before -thwap-
I realized that the `+' in the filename was causing the problem.

Without making a promise about my accuracy, I did search for other calls 
to `string-match' in org-publish.el and thought that they all looked 
good. I think the problem can only occur when a regexp is being created 
from a non-regexp string passed in by the user. In this case, a file path.

I did not search in any other org source files.

Neil

(defun org-publish-get-project-from-filename (filename &optional up)
   "Return the project that FILENAME belongs to."
   (let* ((filename (expand-file-name filename))
	 project-name)

     (catch 'p-found
       (dolist (prj org-publish-project-alist)
	(unless (plist-get (cdr prj) :components)
	  ;; [[info:org:Selecting%20files]] shows how this is supposed to work:
	  (let* ((r (plist-get (cdr prj) :recursive))
		 (b (regexp-quote             <-- !!!!!HERE!!!!!
                      (expand-file-name (file-name-as-directory
                                         (plist-get (cdr prj) 
:base-directory)))))
		 (x (or (plist-get (cdr prj) :base-extension) "org"))
		 (e (plist-get (cdr prj) :exclude))
		 (i (plist-get (cdr prj) :include))
		 (xm (concat "^" b (if r ".+" "[^/]+") "\\.\\(" x "\\)$")))
	    (when
		(or
		   (and
		  i (member filename
			    (mapcar
			     (lambda (file) (expand-file-name file b))
			     i)))
		   (and
		    (not (and e (string-match e filename)))
		    (string-match xm filename)))
	      (setq project-name (car prj))
	      (throw 'p-found project-name))))))
     (when up
       (dolist (prj org-publish-project-alist)
	(if (member project-name (plist-get (cdr prj) :components))
	    (setq project-name (car prj)))))
     (assoc project-name org-publish-project-alist)))

-- 
Neil Smithline
http://www.neilsmithline.com
Proud GNU Emacs user since 1986, v. 18.24.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-05-14  2:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-14  2:27 one line fix for org-publish-get-project-from-filename when filename has regexp chars in it Neil Smithline

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).