From mboxrd@z Thu Jan 1 00:00:00 1970 From: Neil Smithline Subject: 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 Message-ID: <4FB06D8F.8080302@neilsmithline.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([208.118.235.92]:49017) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1STl0Y-0007Zp-D1 for emacs-orgmode@gnu.org; Sun, 13 May 2012 22:27:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1STl0W-0007Er-Bi for emacs-orgmode@gnu.org; Sun, 13 May 2012 22:27:33 -0400 Received: from mail-qa0-f48.google.com ([209.85.216.48]:54815) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1STl0W-0007EU-7c for emacs-orgmode@gnu.org; Sun, 13 May 2012 22:27:32 -0400 Received: by qady23 with SMTP id y23so3354876qad.14 for ; Sun, 13 May 2012 19:27:29 -0700 (PDT) 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: 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.