emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] one line fix for org-publish-get-project-from-filename when filename


From: Neil Smithline
Subject: [O] one line fix for org-publish-get-project-from-filename when filename has regexp chars in it
Date: Sun, 13 May 2012 22:27:27 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:14.0) Gecko/20120429 Thunderbird/14.0a2

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]