help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Reuse frame with emacsclient and/or use shell aliases when finding f


From: Thien-Thi Nguyen
Subject: Re: Reuse frame with emacsclient and/or use shell aliases when finding files
Date: Sat, 31 May 2014 13:21:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

() Jacob Gerlach <jacobgerlach@gmail.com>
() Fri, 30 May 2014 18:57:19 -0700 (PDT)

   I wonder if I could come up with some utility
   function to read in bash aliases and create the
   associated dired bookmarks when I start emacs.

Probably yes, if you learn a small bit of Emacs Lisp.
Personally, i define an env var for each directory:

Attachment: .directory-env-vars
Description: application/emacs-lisp

Attachment: jamenv.el
Description: application/emacs-lisp

and type (for example) ‘C-x C-f $go/gnugo.el’ to visit
/home/ttn/build/GNU/elpa/packages/gnugo/gnugo.el.

Recent Emacs versions can do completion, and even on
the env vars!  (I marvel at this, taken aback by the
mega-cycles burned for such banalities -- i guess i
prefer a more lizard-like less-electric lifestyle...
[insert more curmudgeonly harumphing] here.)

The "scads of short env vars" approach has, over the
years, tickled bugs in various tools that presume such
env vars are not set, which was annoying at the time,
but good for all (me and tools) over the long run,
once the tools' authors made them more mindful.

I also instrument ‘M-x compile’ like so:

 (defun rewrite-shell-command-w/cd (string)
   "If STRING begins w/ \"$foo\", return a new string.
 In the new string, the \"$foo\" is replaced with \"cd $foo\", and
 furthermore \"$foo\" is replaced with the value of `(getenv \"foo\")'.
 
 For example, if (getenv \"hack\") => \"~/build/hack\", then
   (rewrite-shell-command-w/cd \"$hack.b ; echo $hack\")
   => \"cd ~/build/hack.b ; echo $hack\"
 
 For other values of STRING, simply return it."
   (save-match-data
     (if (string-match "^[$]\\([a-zA-Z_]+\\)" string)
         (replace-match (concat "cd " (getenv (match-string 1 string)))
                        t t string)
       string)))

 (defadvice compilation-start (before rewrite-compilation-command-w/cd activate)
  "Replace COMMAND using `rewrite-shell-command-w/cd'."
  (ad-set-arg 0 (rewrite-shell-command-w/cd (ad-get-arg 0))))

and bind ‘M-m’ to ‘compile’, such that (for example)

 M-m $go ; git remote update RET

invokes the "git remote update" command in directory
/home/ttn/build/GNU/elpa/packages/gnugo, no matter
what the ‘default-directory’ (from current buffer) is
at ‘M-m’ time.  This is a small step towards the yet-
unrealized ideal of having the env var expanded in the
command, itself, which involves phasing complications
for the expansion of "~", primarily.  Maybe Some Day...

-- 
Thien-Thi Nguyen
   GPG key: 4C807502
   (if you're human and you know it)
      read my lisp: (responsep (questions 'technical)
                               (not (via 'mailing-list)))
                     => nil

Attachment: signature.asc
Description: PGP signature


reply via email to

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