unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Josh <josh@foxtail.org>
To: Jarek Czekalski <jarekczek@poczta.onet.pl>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: run/load a lisp script before user init file
Date: Tue, 8 Oct 2013 12:34:26 -0700	[thread overview]
Message-ID: <CANdFEAHeO-8v-AVNQv_0W47_W3V8ngtZZm+gjB4vCKd+x6uQWw@mail.gmail.com> (raw)
In-Reply-To: <52541BA7.6060909@poczta.onet.pl>

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

On Tue, Oct 8, 2013 at 7:50 AM, Jarek Czekalski <jarekczek@poczta.onet.pl>
wrote:
> My attempts to establish a portable way to do that may be
> annoying. I can understand that. So I finish this thread. My
> conclusion is:
>
> The site-start design is a mistake. That's why all installers say:
> add "..."  to your init file. That's the way I'm going to choose
> too. Until someone revises the design and comes up with something
> comfortable. Debian folks would do that, but apparently they
> decided that it's easier to create own solution, than to fight for
> the improvement in core.

If you choose to use init files alone, you may be able to take advantage
of the order in which Emacs searches for init files.  The manual[0]
documents three init files that are checked, but _not_ the order in which
Emacs looks for them (this is arguably a documentation bug, but be aware
that this order could change since the documentation currently makes no
promises about it).  For the moment though, a quick command-line
experiment here in Bash[1] showed that Emacs looks first for ~/.emacs.el,
then for ~/.emacs, and finally for ~/.emacs.d/init.el.  You could place a
minimal bootstrap init file in ~/.emacs.el which would do nothing but
load Emacspeak if possible and then immediately try to load the main init
file where users' configuration would be stored.  By making an
appropriate assignment to user-init-file it preserves users' ability to
store customization settings in their own init files where your package
need never touch them.  It is perfectly safe to create and remove this
bootstrap file when installing and uninstalling your package so long as
you verify that it does not yet exist before creating it and that its
contents remain unchanged before deleting it.  After uninstallation of
your package and removal of the bootstrap code in ~/.emacs.el, all of the
contents of your users' ~/.emacs and/or ~/.emacs.d/init.el will remain
intact and Emacs will find them normally after failing to find the
deleted ~/.emacs.el.  Here is an example of what I'm suggesting (lightly
tested):

;; add emacspeak to `load-path' here if necessary
(message "Loading Emacspeak...%s"
         (if (load "emacspeak-loader" :noerror) "success!" "FAILED!"))

;; Fall back to this file if neither ~/.emacs nor ~/.emacs.d/init.el
;; could be found, though creating one of those may be preferable to
;; avoid the possibility of user customization ending up here and
;; complicating uninstallation of your package.
(let ((fallback-user-init-file user-init-file))
  (if (string-equal user-init-file (expand-file-name "~/.emacs.el"))
      (unless (load (setq user-init-file
                          (expand-file-name "~/.emacs"))
                    :noerror nil :nosuffix)
        (unless (load (setq user-init-file
                            (expand-file-name "~/.emacs.d/init.el"))
                      :noerror nil :nosuffix)
          (setq user-init-file fallback-user-init-file)))
    (error "init bootstrap code found in %s but must reside in ~/.emacs.el"
           user-init-file)))

;; (message "final user-init-file: %s" user-init-file)
;; -> /path/to/HOME/.emacs, or if not found
;;    /path/to/HOME/.emacs.d/init.el, or if not found
;;    /path/to/HOME/.emacs.el (this file)

HTH,
Josh

[0] (info "(elisp) Init File")
[1] ( fakehome="/tmp/fakehome"; if [ -d $fakehome ] ; then echo "$fakehome
exists, aborting" ; exit 1 ; else export HOME="$fakehome"; mkdir -p
${HOME}/.emacs.d && cd && for f in .emacs .emacs.el .emacs.d/init.el ; do
echo "(message \"$f\")" >$f ; done ; emacs -nw --eval '(message
"user-init-file: %s" user-init-file)' ; fi )

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

  parent reply	other threads:[~2013-10-08 19:34 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-07 15:24 run/load a lisp script before user init file Jarek Czekalski
2013-10-07 16:43 ` Eli Zaretskii
2013-10-07 18:42   ` Jarek Czekalski
2013-10-07 19:00     ` Eli Zaretskii
2013-10-07 19:37       ` Jarek Czekalski
2013-10-07 20:08         ` Eli Zaretskii
2013-10-07 22:52           ` Stefan Monnier
2013-10-08  5:52             ` Jarek Czekalski
2013-10-08  6:27               ` Stephen J. Turnbull
2013-10-08  6:40                 ` Harald Hanche-Olsen
2013-10-08 13:09                   ` Stephen J. Turnbull
2013-10-08 14:30                     ` Jarek Czekalski
2013-10-08 14:36                     ` Jarek Czekalski
2013-10-08 14:50                       ` Jarek Czekalski
2013-10-08 16:01                         ` Stephen J. Turnbull
2013-10-08 19:34                         ` Josh [this message]
2013-10-08  6:46                 ` Jarek Czekalski
2013-10-08 16:22                   ` Glenn Morris
2013-10-08 17:30                     ` Tom Tromey
2013-10-09  1:56                       ` Stephen J. Turnbull
2013-10-08 21:47                     ` Jarek Czekalski
2013-10-08  6:16       ` Kevin Rodgers
  -- strict thread matches above, loose matches on Subject: below --
2013-10-10 13:52 Barry OReilly
2013-10-10 16:11 ` Josh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANdFEAHeO-8v-AVNQv_0W47_W3V8ngtZZm+gjB4vCKd+x6uQWw@mail.gmail.com \
    --to=josh@foxtail.org \
    --cc=emacs-devel@gnu.org \
    --cc=jarekczek@poczta.onet.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).