[Top][All Lists]

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

Re: Default share/ and lisp/ directories?

From: Kaushal Modi
Subject: Re: Default share/ and lisp/ directories?
Date: Tue, 20 Feb 2018 20:27:01 +0000

On Tue, Feb 20, 2018 at 1:48 PM Drew Adams <address@hidden> wrote:
Suggestion: use functions for manipulating file/dir names.

Use (file-name-directory (directory-file-name (expand-file-name file)))

Thank you. I was aware of that, but was just being plain lazy.. I didn't consider refactoring my whole config to fix that until now[1], so thanks :)

Here's the improved code:

(let* ((bin-dir (when (and invocation-directory
                           (file-exists-p invocation-directory))
                  (file-truename invocation-directory)))
       (prefix-dir (when bin-dir        ;Because bin-dir = prefix-dir + "bin/"
                     (file-name-directory (directory-file-name bin-dir))))
       (share-dir (when (and prefix-dir
                             (file-exists-p prefix-dir))
                    (file-name-as-directory (expand-file-name "share" prefix-dir))))
       (emacs-dir (when (and share-dir
                             (file-exists-p share-dir))
                    (file-name-as-directory (expand-file-name "emacs" share-dir))))
       (version-dir (when emacs-dir
                      ;; Possibility where the lisp dir is something like
                      ;; ../emacs/26.0.50/lisp/.  If `emacs-version' is x.y.z.w,
                      ;; remove the ".w" portion.  Though, this is not needed
                      ;; for emacs 26+, and also will do nothing in that case.
                      ;; http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=22b2207471807bda86534b4faf1a29b3a6447536
                      (let* ((version (replace-regexp-in-string "\\([0-9]+\\.[0-9]+\\.[0-9]+\\).*" "\\1" emacs-version))
                             (version-dir-1 (file-name-as-directory (expand-file-name version emacs-dir))))
                        (if (file-exists-p version-dir-1)
                          ;; Possibility where the lisp dir is something like
                          ;; ../emacs/25.2/lisp/.  If `emacs-version' is x.y.z,
                          ;; remove the ".z" portion.
                          (setq version (replace-regexp-in-string "\\([0-9]+\\.[0-9]+\\).*" "\\1" emacs-version))
                          (setq version-dir-1 (file-name-as-directory (expand-file-name version emacs-dir)))
                          (when (file-exists-p version-dir-1)
       (lisp-dir (file-name-as-directory (expand-file-name "lisp" version-dir))))
  (defvar modi/default-share-directory (when (file-exists-p share-dir)
    "Share directory for this Emacs installation.")
  (defvar modi/default-lisp-directory (when (file-exists-p lisp-dir)
    "Directory containing lisp files for the Emacs installation.

This value must match the path to the lisp/ directory of the
Emacs installation.  If Emacs is installed using
--prefix=\"${PREFIX_DIR}\" this value would typically be

I think it would be useful to include the share/ and lisp/ dirs stored in some variable in emacs core, just like invocation-directory.


Kaushal Modi

reply via email to

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