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
This commit is contained in:
Carsten Dominik 2009-11-11 08:41:44 +01:00
parent 3ebaffe07e
commit 8d7d158013
1 changed files with 17 additions and 16 deletions

View File

@ -102,28 +102,29 @@
"Show the org-mode version in the echo area. "Show the org-mode version in the echo area.
With prefix arg HERE, insert it at point." With prefix arg HERE, insert it at point."
(interactive "P") (interactive "P")
(let* ((version org-version) (let* ((origin default-directory)
(version org-version)
(git-version) (git-version)
(dir (concat (file-name-directory (locate-library "org")) "../" ))) (dir (concat (file-name-directory (locate-library "org")) "../" )))
(if (and (file-exists-p (expand-file-name ".git" dir)) (when (and (file-exists-p (expand-file-name ".git" dir))
(executable-find "git")) (executable-find "git"))
(let ((pwd (substring (pwd) 10))) (unwind-protect
(progn
(cd dir) (cd dir)
(if (eql 0 (shell-command "git describe --abbrev=4 HEAD")) (when (eql 0 (shell-command "git describe --abbrev=4 HEAD"))
(with-current-buffer "*Shell Command Output*" (with-current-buffer "*Shell Command Output*"
(goto-char (point-min)) (goto-char (point-min))
(re-search-forward "[^\n]+") (setq git-version (buffer-substring (point) (point-at-eol))))
(setq git-version (match-string 0))
(subst-char-in-string ?- ?. git-version t) (subst-char-in-string ?- ?. git-version t)
(shell-command "git diff-index --name-only HEAD --") (when (string-match "\\S-"
(unless (eql 1 (point-max)) (shell-command-to-string
"git diff-index --name-only HEAD --"))
(setq git-version (concat git-version ".dirty"))) (setq git-version (concat git-version ".dirty")))
(setq version (concat version " (" git-version ")"))) (setq version (concat version " (" git-version ")"))))
(cd pwd)))) (cd origin)))
(setq version (format "Org-mode version %s" version)) (setq version (format "Org-mode version %s" version))
(if here (insert version)) (if here (insert version))
(message version) (message version)))
version))
;;; Compatibility constants ;;; Compatibility constants