Category: Emacs

Moved mk-project to github, released v1.0.3

I've separated mk-project from my personal emacs configuration git repository and moved it to github at http://github.com/mattkeller/mk-project.

The code at github is tagged 1.0.3 as I fixed a small bug where the mk-project-open-files-cache variable wasn't reset on project unload.

Technorati tags for this post:

mk-project.el v1.0.2

Thanks to Mihai Bazon for reporting a bug in version 1.0.1 of mk-project. The 'tags-file' directive in project-def should be optional, but Mihai noticed that projects didn't load when they didn't include the directive.

I've uploaded version 1.0.2 to the emacs wiki which includes a fix for the bug and also adds Mercurial support to the library.

Technorati tags for this post:

mk-project.el v1.0.1

I've been working on mk-project.el, my Emacs project library. I wanted to write up the changes I've made.

Bug Fix: Kill TAGS buffer on project-unload

When the project is unloaded, reset the variables use by the tags facility as well as deleting the buffer associated with the project's tags file.

New Feature: Save/restore open files on project-unload/load

When a project is unloaded, store the names of the open project files in a cache file. When loading the project, create buffers for the files listed in the cache file. To enable the feature, specify a cache file with 'open-files-cache' in the project's definition. For example:

(project-def "my-proj"
      '((basedir          "/home/me/my-proj/")
        (src-patterns     ("*.java" "*.jsp"))
        (ignore-patterns  ("*.class" "*.wsdl"))
        (tags-file        "/home/me/my-proj/TAGS")
        (file-list-cache  "/home/me/.my-proj-files")
        (open-files-cache "/home/me/.my-proj-open-files")
        (vcs              git)
        (compile-cmd      "ant")
        (startup-hook     myproj-startup-hook)
        (shutdown-hook    nil)))

New Feature: Version tags in the source

Given that I've already published several versions of this library, I'm a late in adding this. But now the elisp source includes a variable holding the version of the library. The version corresponds to tags in my git repo. I'm calling this version 1.0.1.

Technorati tags for this post:

Singleton Emacs Server

My .emacs file calls server-start so I can use emacsclient from the shell to send random editing jobs to emacs. However, with multiple emacs processes running, I sometimes have to hunt around for the emacs instance that emacsclient sent the editing job to do. Bummer!

I'd prefer emacsclient to send all my editing jobs to a single, known emacs process (unless I tell it to use another). The server-name variable can help with this. The server-name value, which defaults to "server", affects the name of the unix domain socket that emacs opens for emacsclient's use. The default socket file is "/tmp/emacs<user-uid>/server". The command "emacsclient -s <server-name>" uses the socket named <server-name> to send the editing job to the emacs process owning the socket. So it would seem that the following settings in your .emacs would do the trick:

(setq server-name "my-server") 
(start-server)

However, if you start another emacs process, it will clobber the existing socket file and subsequent emacsclient requests to "my-server" will go to the new process. Furthermore, emacs doesn't clean up the socket files on exit. This makes it tough to detect if a server with a particular server-name is running.

Below is a wrapper around server-start that helps. First, it allows you to easily name the server. Secondly, it arranges for emacs to delete the socket files it owns when emacs shuts down. This allows the function to use the existence of the socket file to decide if a server process exists for a given name -- so there is a way to refuse to start the server if an existing emacs process is already running it.

(require 'server)

(defun start-named-server (name)
  "Start a server named 'name' - ensure only 1 server of that name is running"
  (interactive "sServer Name: ")
  (setq server-name name)
  (setq mk-server-socket-file (concat server-socket-dir "/" name))
  (unless (file-exists-p mk-server-socket-file)
    (server-start)
    (add-hook 'kill-emacs-hook
              (lambda ()
                (when (file-exists-p mk-server-socket-file)
                  (delete-file mk-server-socket-file))))))

(start-named-server "server") ; default server-name

Additional emacs instances can start a server via "M-x start-named-server ENTER <server-name>".

Technorati tags for this post:

Another Emacs Project Library

I've posted a new project handling library to the Emacs Wiki: mk-project.el. A "project" in this sense is a directory of source files. You define a named project and provide settings for it: base directory, source file patterns, file patterns to ignore, the TAGS file, the compile command, etc.

Features:

  • Quickly switch between projects, optionally closing the files in the old project.
  • Use the new project's TAGS file -- and be able to rebuild the TAGS file based on project settings.
  • Run find-grep from the new project's base directory, ignoring certain files or directories based on project settings.
  • Run compile with the project's preferred compile command.
  • Open any file in the project quickly based on regex matches.
  • Quickly open dired on the project's base directory.
  • Define per-project startup and shutdown hooks -- useful for opening often-used files.

Perhaps the feature I'm happiest with is project-find-file. The library maintains a list of all the files under the project's base directory in a special buffer, *file-list*. Project-find-file ask for a regular expression representing part of a file's path or name and either 1) opens the file if there is only one match in *file-list*, or 2) allows selecting among the matching files with Emacs' built-in completion mechanism. Also, it sometimes comes in handy to search buffer *file-list* directly when you want an overview of the entire project. I often work with projects having thousands of files in deep folder hierarchies so project-find-file is very convenient.

After writing my library, I discovered a similar library, ProjMan by David Shilvock. The project operations we offer are similar - we even recommend similar keybindings! ProjMan is perhaps more complete, but I don't feel my time was wasted writing mk-project.el -- elisp is pleasure to code in.

Technorati tags for this post:

Re: Classical learning curves for common editors

While I'm on my Vim theme - here's a set of graphs showing learning curves for common editors.

Hilarious!

Technorati tags for this post:

< Future 10 | Past 10 >