unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Default share/ and lisp/ directories?
@ 2018-02-20 18:09 Kaushal Modi
  2018-02-20 18:48 ` Drew Adams
  0 siblings, 1 reply; 4+ messages in thread
From: Kaushal Modi @ 2018-02-20 18:09 UTC (permalink / raw)
  To: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 2421 bytes --]

I have probably heavily over-engineered this; it helps me derive the
default path for "share/" and "lisp/" directories.

I couldn't find any internal variable that holds those values.

Here's the code:

(let* ((bin-dir (when (and invocation-directory
                           (file-exists-p invocation-directory))
                  (file-truename invocation-directory)))
       (prefix-dir (when bin-dir
                     (replace-regexp-in-string "bin/\\'" "" bin-dir)))
       (share-dir (when prefix-dir
                    (concat prefix-dir "share/")))
       (lisp-dir-1 (when share-dir ;Possibility where the lisp dir is
something like ../emacs/26.0.50/lisp/
                     (concat share-dir "emacs/"
                             ;; If `emacs-version' is x.y.z.w, remove the
".w" portion
                             ;; Though, this is not needed and also will do
nothing in emacs 26+
                             ;;
http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=22b2207471807bda86534b4faf1a29b3a6447536
                             (replace-regexp-in-string
"\\([0-9]+\\.[0-9]+\\.[0-9]+\\).*" "\\1" emacs-version)
                             "/lisp/")))
       (lisp-dir-2 (when share-dir ;Possibility where the lisp dir is
something like ../emacs/25.2/lisp/
                     (concat share-dir "emacs/"
                             (replace-regexp-in-string
"\\([0-9]+\\.[0-9]+\\).*" "\\1" emacs-version)
                             "/lisp/"))))
  (defvar modi/default-share-directory (when (file-exists-p share-dir)
                                         share-dir)
    "Share directory for this Emacs installation.")
  (defvar modi/default-lisp-directory (cond
                                       ((file-exists-p lisp-dir-1)
                                        lisp-dir-1)
                                       ((file-exists-p lisp-dir-2)
                                        lisp-dir-2)
                                       (t
                                        nil))
    "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
\"${PREFIX_DIR}/share/emacs/<VERSION>/lisp/\"."))

- Are there internal variables that hold those values?
- Is there a better way to do the same?
-- 

Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 3648 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Default share/ and lisp/ directories?
  2018-02-20 18:09 Default share/ and lisp/ directories? Kaushal Modi
@ 2018-02-20 18:48 ` Drew Adams
  2018-02-20 20:27   ` Kaushal Modi
  0 siblings, 1 reply; 4+ messages in thread
From: Drew Adams @ 2018-02-20 18:48 UTC (permalink / raw)
  To: Kaushal Modi, Emacs developers

Suggestion: use functions for manipulating file/dir names.

> (let* ((bin-dir (when (and invocation-directory
>                            (file-exists-p invocation-directory))
>                   (file-truename invocation-directory)))
>        (prefix-dir (when bin-dir
>                      (replace-regexp-in-string "bin/\\'" "" bin-dir)))

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

More generally (from dired+.el):

(defun parent-dir (file &optional relativep)
  "Return the parent directory of FILE, or nil if none.
Optional arg RELATIVEP non-nil means return a relative name, that is,
just the parent component."
  (let ((parent  (file-name-directory (directory-file-name (expand-file-name file))))
        relparent)
    (when relativep (setq relparent  (file-name-nondirectory (directory-file-name parent))))
    (and (not (equal parent file))  (or relparent  parent))))

> (when prefix-dir (concat prefix-dir "share/"))

Use (file-name-as-directory (expand-file-name "share" prefix-dir))



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Default share/ and lisp/ directories?
  2018-02-20 18:48 ` Drew Adams
@ 2018-02-20 20:27   ` Kaushal Modi
  2018-02-20 21:06     ` Noam Postavsky
  0 siblings, 1 reply; 4+ messages in thread
From: Kaushal Modi @ 2018-02-20 20:27 UTC (permalink / raw)
  To: Drew Adams; +Cc: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 3325 bytes --]

On Tue, Feb 20, 2018 at 1:48 PM Drew Adams <drew.adams@oracle.com> 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)
                            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)
                            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-dir)
    "Share directory for this Emacs installation.")
  (defvar modi/default-lisp-directory (when (file-exists-p lisp-dir)
                                        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
\"${PREFIX_DIR}/share/emacs/<VERSION>/lisp/\"."))

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

[1]:
https://github.com/kaushalmodi/.emacs.d/commit/64b0c3fbf3372bd96a32d1f24d9adeb9112abd08
-- 

Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 4879 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Default share/ and lisp/ directories?
  2018-02-20 20:27   ` Kaushal Modi
@ 2018-02-20 21:06     ` Noam Postavsky
  0 siblings, 0 replies; 4+ messages in thread
From: Noam Postavsky @ 2018-02-20 21:06 UTC (permalink / raw)
  To: Kaushal Modi; +Cc: Drew Adams, Emacs developers

On Tue, Feb 20, 2018 at 3:27 PM, Kaushal Modi <kaushal.modi@gmail.com> wrote:

>> 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 :)

For those of us who are even lazier, what's wrong with

(defvar share-dir (expand-file-name "../share/" invocation-directory))
(defvar lisp-dir
  (expand-file-name
   (format "../share/emacs/%s/lisp/"
           (pcase (version-to-list emacs-version)
             (`(,major 0 ,micro . ,_) (format "%d.0.%d" major micro))
             (`(,major ,minor . ,_) (format "%d.%d" major minor))))
   invocation-directory))



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-02-20 21:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-20 18:09 Default share/ and lisp/ directories? Kaushal Modi
2018-02-20 18:48 ` Drew Adams
2018-02-20 20:27   ` Kaushal Modi
2018-02-20 21:06     ` Noam Postavsky

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).