XEmacs

IDEs are all the rage in software development, but I’ve remained a devote Emacs user, or XEmacs to be more precise. Why? Primarily because XEmacs is primarily for editing files, and does the job extremely well. It can be customized to a great extent, where XEmacs is truly a platform in itself, allowing the user to tailor it to their needs. But even out of the box, XEmacs is phenomenally powerful, making it trivial to record keystrokes and record those as macros (hence the “mac” part of the name).

Some nifty XEmacs tricks:

  • Transposing two characters: control-t
  • Transposing two words: alt-t. This is all the more powerful in that words can be “dragged” forward by repeated alt-t sequences. And XEmacs mysteriously knows how to skip punctuation, making it very useful for when method arguments need to be reordered.
  • Transposing lines: switch the current line with the previous: control-x-control-t.
  • Reindenting code: highlight the region, then escape-ctrl-backslash (C-M-\ in Emacs-speak).
  • Inserting the basename of the current file. This is useful in Java code, where the file basename is the same as the public class in that file. This bit of Emacs Lisp does it:
  • (defun jep:file-split (file)
      "Split file name x.y by dot, returning the list (x y)."
      (let* (fn
    	 ;; extended so that foo.cpp => foo.cpp
    	 (re  "^\\(.*\\)[.]\\([^<]*\\)")
             ext)
    
        (if (not (and (string-match re file)
                      (match-end 1) (match-end 2) ))
            nil
          (setq fn  (substring file (match-beginning 1) (match-end 1)))
          (setq ext (substring file (match-beginning 2) (match-end 2)))
          )
    
        ; return a list containing the file name and the extension
        (if (and fn ext)
            (list fn ext)
          nil)
        ))
    
    (defun jep:file-basename ()
      "Returns the file name, minus the directory and suffix."
      (let* ((bn (buffer-name))
             (namelist (jep:file-split bn))
             fn
             )
    
        (if (or (null namelist) (= 1 (length namelist)))
            nil
          
          ;; first in the name list is the file name; second is the extension
          (setq fn  (nth 0 namelist))
          fn)))
    
    (defun jep:file-insert-basename ()
      "Inserts the basename at the current point."
      (interactive)
      (let* ((fn (jep:file-basename))
             )
        ;; Not doing a save-excursion, because we want to go to the end of what we
        ;; inserted.
        (insert fn)
        ))
    
    
    

That’s just a start; I’ll add more later.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s