Sunday·26·April·2009
Screen and Emacsclient: Automatically switching to the Emacs window //at 10:38 //by abe
For a very long time, I use mutt with emacsclient as configured editor
and a single GNU Emacs instance started from either .screenrc
or .Xsession
, depending on the system. And I’m very used to
switching the virtual desktop or the screen window after starting a
mail in mutt.
Since Debian 5.0 Lenny and Emacs 22, Emacs automatically grabs the
focus and switches to the right virtual desktop. So after telling mutt
recipient and subject of a new e-mail, it invokes emacsclient and
immediately the focus has moved to the running Emacs instance. Because
I was used to switch one virtual desktop to the right at that point, I
often found my self two desktops to the right until I got used to it.
:-)
I usually hate applications which grab the focus without being asked. But in this case I basically asked for it. And there’s no delay like with starting up an application which has to read in some database first – think of Liferea or Rhythmbox which take many seconds to minutes to start up, even on my 2.2 GHz dual core ThinkPad.
In the meantime I got so used to that automatic desktop switch that I forget to switch the screen window in the second scenario where I use this combination: My screen doesn’t automatically switch to the Emacs window (window 1) after I told mutt recepient and subject in window 2.
Knowing that screen is quite scriptable, I found out that only a very
small change is needed to my mutt configuration to get that desktop
feature to my everyday screen session. I simply replaced the editor
setting in my .muttrc
with the following
line:
set editor="screen -X select 1;emacsclient"
Now mutt tells screen to switch to window 1 (where Emacs is running) and then tells Emacs to open the appropriate file to edit my new mail.
Update Friday, 2009-04-24, 18:22
Even though Zack surely is right with his comment about the multi-terminal feature of the upcoming GNU Emacs 23, I still have Etch (and therefore GNU Emacs 21) on the server where I have my screen session.
So the next step was to switch back to the mutt window (window 2)
after I’m finished with editing the mail. Since mutt gives the the
file to edit as argument to the contents of $editor
,
simply adding ;screen -X select 2
at the end of
$editor
doesn’t suffice.
So I wrote a small shell script (named ~/.mutt/editor.sh
) as wrapper which calls all the
commands and passes the parameters to the right command:
#!/bin/sh screen -X select 1 emacsclient -a ~/.mutt/alteditor.sh "$@" screen -X select 2
Of course, $editor
is now set to that script:
set editor="/home/abe/.mutt/editor.sh"
Emacsclient of GNU Emacs 21 already supports the -a
option to call
another editor in case of not being able to connect to a running Emacs
instance. Since I don’t want to switch to another screen window in
that case, I wrote a second shell script (named ~/.mutt/alteditor.sh
) which switches back to the mutt window
and then calls GNU Zile, my preferred low-end emacs clone:
#!/bin/sh screen -X select 2 zile "$@" screen -X select 1
I love it!
Tagged as: $EDITOR, Debian, E-Mail, Emacs, Emacs21, Emacs22, Emacs23, emacsclient, Etch, GNU Screen, Lenny, mutt, screen, scripting, zile
3 comments // show without comments // write a comment
Related stories
Wednesday·15·April·2009
Useless Statistics, the 2nd //at 19:35 //by abe
Myon recently posted a nice statistic about popular single letter package name prefixes. Just out of curiosity I started wondering about popular single letter package name suffixes:
On a machine with Debian oldstable, stable, testing, unstable and experimental in its sources.list, I ran the following command:
$ apt-cache search -n . | \ awk '{print $1}' | \ sed -e 's/.$//' | \ sort | \ uniq -c | \ sort -n
And to my surprise there is a non-obvious winner:
$ apt-cache search -n '^gp.$' gpa - GNU Privacy Assistant gpc - The GNU Pascal compiler gpe - The G Palmtop Environment (GPE) metapackage gpm - General Purpose Mouse interface gpp - a general-purpose preprocessor with customizable syntax gpr - GUI for lpr: print files and configure printer-specific options gps - Graphical Process Statistics using GTK+ gpt - G-Portugol is a portuguese structured programming language gpw - Trigraph Password Generator
But since I searched through the binary packages many other hits are more obvious, like the seven packages hbf-cns40-1 to hbf-cns40-7:
[...] 4 ar 4 aspell-f 4 automake1. 4 cpp-4. 4 e 4 g++-4. 4 gappletviewer-4. 4 gcc-4. 4 gcj-4. 4 gcompris-sound-e 4 gfortran-4. 4 gij-4. 4 go 4 gobjc-4. 4 gobjc++-4. 4 h 4 iceweasel-l10n-e 4 iceweasel-l10n-k 4 kde-i18n-f 4 kde-i18n-h 4 kde-l10n-e 4 kde-l10n-s 4 kile-i18n-e 4 koffice-i18n-e 4 koffice-i18n-s 4 koffice-l10n-e 4 koffice-l10n-f 4 libqbanking 4 myspell-f 4 myspell-h 4 openoffice.org-help-e 4 openoffice.org-l10n-b 4 openoffice.org-l10n-h 4 openoffice.org-l10n-k 4 sd 4 tcl8. 4 tk8. 5 aspell-e 5 aspell-h 5 iceweasel-l10n-s 5 kde-i18n-b 5 kde-i18n-e 5 kde-i18n-t 5 kde-l10n-k 5 openoffice.org-l10n-e 5 openoffice.org-l10n-t 5 pa 5 tc 6 gc 6 kde-i18n-s 6 libdb4. 6 m 6 openoffice.org-l10n-n 6 openoffice.org-l10n-s 6 s 7 hbf-cns40- 9 gp
But there are also some other interesting observations to make:
- OpenOffice.org seems to have by far the biggest number of localisations, with KDE being 2nd.
- There are 6 version of the Berkeley DB in Debian: libdb4.2 to libdb4.7 (including oldstable as mentioned above)
I leave it as an exercise to the reader to find the full names of the
other package names starting with s, m, gc, pa or tc and having just
one additional character. ;-)
Tagged as: Debian, Etch, Lenny, Myon, names, Other Blogs, packages, Planet Debian, scripting, Sid, Squeeze, statistics
0 comments // show without comments // write a comment