Archive for category Emacs

Setting your Emacsens default directory when launched through a custom keyboard shortcut

Posted by on Monday, 2 April, 2012

I noticed that Emacs was getting a default-directory value of / when launching it with a custom keyboard shortcut I set up in Gnome (2). The result is that opening a file started my search in the root (/) of the filesystem.

I suppose this is due to the way in which emacs was invoked (via the window manager). Given that there was no actual present working directory, I can understand that it would default back to using /.

At the time I was just setting the window title:

emacs -T Emacs

When considering how to work around this I first considered setting the default-directory in my .emacs file. This turned out to be a less an idea solution. Doing so causes it to become a global configuration value (all subsequent emacs launched via the terminal opened in ~). So instead, I changed my launcher command to this:

emacs -T Emacs -eval "(setq default-directory \"~/\")"

Works like a champ!

Excluding in the Emacs file completion buffer

Posted by on Tuesday, 3 January, 2012

I realized tonight While hacking on Taboot that Emacs was showing particularly uninteresting files in the completion buffer when opening a file. For example, scripts.pyc.

I assumed that there was a facility for customizing this, so I did some research on the topic. Trying emacs filter possible completions and emacs filter list of completions both came up with the same documentation. The GNU documentation describes a customization facility similar to the filtering I sought after via the completion-ignored-extensions variable (part of the Dired group). However, it stops a bit short of what I was looking for. Quote from describe-variable for the variable (emphasis added):

Completion ignores file names ending in any string in this list. It does not ignore them if all possible completions end in one of these strings or when displaying a list of completions.

I went through some more search results and sure enough, stackoverflow provides again. In that response the author provided a fantastic defadvice which did exactly what I was looking for. By default it uses the value of your existing completion-ignored-extensions variable.

Lots more docs published on PeopleAreDucks.com

Posted by on Wednesday, 22 September, 2010

While I’ve been gone from the blogging world I’ve still been working on projects. Mostly I’ve been working on documentation.

  • Debian/Fedora Package Management comparison. Since switching my Slice to Fedora from Ubuntu I’ve picked up plenty of commands for managing packages. This is just a quick wiki page giving the roughly equivalent commands from Debian/Ubuntu to Fedora/RedHat.
  • regexp basics is a brief tutorial on regular expressions. My roommate abutcher put it together for his WVU CS210 (Advanced File and Data Structures) course. The DocBook 5 sources are available in git.
  • The biggest doc project I’ve been working on again (finally) is my Virtual Disk Guide aimed at power users and sysadmins. Currently it’s a rough draft and is constantly undergoing major changes and additions. It’s available as a single HTML document, chunked into multiple pages, and in PDF format. You can get the DocBook 5 formatted source to it through my GitHub account.

My Project Templates project has seen some much needed attention recently. The DocBook starter project has been completely redone. Here’s some reasons you might want to use it.

  • Includes a basic starter document with most of the available informational tags present but commented out so all you need to do is uncomment the elements you need for your document.
  • Inclues a customizable Makefile that can adapt itself to different operating systems (Debian/Ubuntu, Fedora/RedHat, and Mac OS X) by just uncommenting the proper directory paths for the schema and stylesheet files.
  • The Makefile has targets for: cleaning up, creating schema locator files for nxml-mode in emacs, publishing PDFs, and publishing chunked or single HTML documents.
  • The comments in the Makefile also tell you what packages you need to install to get the schema and stylesheet files.

Using the Makefile for publishing only requires having xsltproc and dblatex installed. Both of which are available through your favorite package manager.

Zone out completely

Posted by on Friday, 26 March, 2010

While searching for modes which would help me edit bind9 configuration files I came across this mailing list post. It mentions zone-mode which ended up being great for editing the actual zone files A+. It also tipped me off to another emacs Easter Egg, M-x zone. Described thus:

zone is an interactive compiled Lisp function.
It is bound to <menu-bar> <tools> <games> <zone>.
(zone)
Zone out, completely.

It’s basically an emacs screensaver/psychedelic ascii mode using your focused buffer for content. It obfuscates the buffer in ways which involves wrapping your code around the screen or swapping characters around, and even just turning it all into curly braces and wiggling. Press a key to undo it all. Might be a neat trick to play on a friend, but I see no other usage for this mode.

Macports updates their Erlang version, update your load-path’s

Posted by on Wednesday, 3 February, 2010

I’ve been working on my XMPP server pet project recently, and the need for a good Erlang XML parser has finally struck. I decided to go with Erlsom. It’s in MacPorts, so from there I installed it. Now, since I don’t update my port tree frequently I get delightful surprises from time to time. This time installing Erlsom triggered an update of Erlang, to the latest version!

Short story shorter, the update changes the path to the erlang-mode.el file so before you can M-x erlang-mode again you’ll have you fix your Emacs load-path to register the new location. (See my older post on how to initially set up Erlang and Emacs from MacPorts from scratch)

The new load commands should be:

(setq load-path (cons  "/opt/local/lib/erlang/lib/tools-2.6.5/emacs/" load-path))
(setq erlang-root-dir "/opt/local/lib/erlang")
(setq exec-path (cons "/opt/local/bin" exec-path))
(require 'erlang-start)

It just requires changing the tools-x.x.x to 2.6.5.

p.s. about erlang-mode

Macports, and Erlang: Setting up Emacs and your $MANPATH

Posted by on Wednesday, 2 December, 2009

You may find this helpful if you should find yourself using Erlang on OS X and you’ve installed it using Macports. After a default installation you’ll need to manually configure your .emacs file for erlang-mode and set your $MANPATH variable correctly, here’s how.

If you’ve installed Erlang with Macports then you may have noticed that when you edit .erl files you’re not entering into erlang-mode, nor is it available to enter into. Here’s how I got erlang-mode working on my system.

Macports will install Erlang into /opt/local/lib/erlang by default. The paths to put in your .emacs file provided in the erlang-mode documentation only need to be tweaked a slight bit to function properly. Here’s what I put in mine:

(setq load-path (cons  "/opt/local/lib/erlang/lib/tools-2.6.4/emacs/" load-path))
(setq erlang-root-dir "/opt/local/lib/erlang")
(setq exec-path (cons "/opt/local/bin" exec-path))
(require 'erlang-start)

Note that you may require setting “tools-2.6.4″ to something else if Macports has upgraded it’s distribution of Erlang.

Setting up your $MANPATH variable is fairly simple as well. Just put the string “/opt/local/lib/erlang/man” in a file called ‘erlang’ in /etc/manpaths.d/ and make sure it ends with an empty line. Test this by opening a new terminal and running: echo $MANPATH | grep erlang. If it doesn’t come back empty then you’ve done it right.

Emacs Hacking, reverse other buffer

Posted by on Sunday, 18 October, 2009

I started reading Writing GNU Emacs Extensions by Bob Glickstein. The first real meaty example you work through in it is making an ‘other-buffer’ like key command that works in reverse. So here I present to the internet, my version of previous-window.

(defun previous-window ()
  "As other-buffer, except in the other-direction"
  (interactive)
  (other-window -1))
 
(global-set-key "\C-c\o" 'previous-window)

Put in your .emacs file and activate with C-c o when you have multiple frames open at once.

Enabling automatic slash completion in nXML-Mode

Posted by on Thursday, 13 August, 2009

I do a lot of DocBook XML editing, either at my job or at home. Because of that I’ve built up a pretty customized .emacs file. Every so often I meet another person whose also found themselves having to edit a bunch of XML. The most fantastic thing about nXML mode I think is the automatic slash completion feature. It works like this: If I have an open element, say I’ve started an <xref>, you can configure nXML mode such that upon typing the closing </ characters it will complete that sequence for you. I can just never remember how to set that option in emacs. So today I’m taking the time to finally document that procedure.

  1. Enter nxml-mode
  2. M-x customize-apropos
  3. nxml-slash
  4. Press Toggle on
  5. Optionally: select “Save for future sessions”

For even more fun, use the C-c C-f macro which will auto complete your current block, regardless of your position inside of it. For additional references, I invite you to check out the docs NM Tech has posted on nXML-Mode.