From 8d7d158013a3642af8239075fd7cfb39adfc518d Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Wed, 11 Nov 2009 08:41:44 +0100 Subject: [PATCH] Restore working directory after computing org-version Sebastian Rose writes > 1. Open an *.org file you can export to PDF. Ensure the file is not > located where your Org-mode sources are (org-*.el files). Choose a > file, that includes some images or a SETUPFILE using relative > paths. > 2. M-x default-directory RET > to see the value of that variable in the current buffer. > 3. C-c C-e p > to export to PDF and verify it works. > 4. C-c C-x ! > to `org-reload' > 5. Now repeat steps 2 and 3. Note, that the export fails. Sebastian also submitted the basic patch to fix this --- lisp/org.el | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index dd34816b4..c0afd10b2 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -102,28 +102,29 @@ "Show the org-mode version in the echo area. With prefix arg HERE, insert it at point." (interactive "P") - (let* ((version org-version) + (let* ((origin default-directory) + (version org-version) (git-version) (dir (concat (file-name-directory (locate-library "org")) "../" ))) - (if (and (file-exists-p (expand-file-name ".git" dir)) - (executable-find "git")) - (let ((pwd (substring (pwd) 10))) - (cd dir) - (if (eql 0 (shell-command "git describe --abbrev=4 HEAD")) + (when (and (file-exists-p (expand-file-name ".git" dir)) + (executable-find "git")) + (unwind-protect + (progn + (cd dir) + (when (eql 0 (shell-command "git describe --abbrev=4 HEAD")) (with-current-buffer "*Shell Command Output*" (goto-char (point-min)) - (re-search-forward "[^\n]+") - (setq git-version (match-string 0)) - (subst-char-in-string ?- ?. git-version t) - (shell-command "git diff-index --name-only HEAD --") - (unless (eql 1 (point-max)) - (setq git-version (concat git-version ".dirty"))) - (setq version (concat version " (" git-version ")"))) - (cd pwd)))) + (setq git-version (buffer-substring (point) (point-at-eol)))) + (subst-char-in-string ?- ?. git-version t) + (when (string-match "\\S-" + (shell-command-to-string + "git diff-index --name-only HEAD --")) + (setq git-version (concat git-version ".dirty"))) + (setq version (concat version " (" git-version ")")))) + (cd origin))) (setq version (format "Org-mode version %s" version)) (if here (insert version)) - (message version) - version)) + (message version))) ;;; Compatibility constants