Tag Archives: Emacs

Managing tasks with Remember The Milk and Emacs

These days I’ve got a lot of stuff to do. There are basics like cleaning the flat or fertilizing plants. There are things connected to my hobbies: remembering to fix a bug or implement a feature in my programs, answering forum posts and emails, practice my choir pieces. And then there’s everything going on at my job: do this for a customer, implement that in a program, and that other internal thing has to be remembered as well.

Too bad I’m forgetting more of those things than I’d like to admit. Fortunately someone invented TODO lists for people like myself.

I’m using the excellent Remember The Milk service (short: RTM) for this kind of thing. The one thing I find absolutely fascinating about RTM is its fast, single keystroke based web interface. Being an avid Emacs user as well I always wanted to be able to access RTM directly from Emacs in nearly the same way. Web searches only turned up an integration into Org mode, which I don’t use and don’t want to learn, I decided to write this myself: SimpleRTM – An Interactive Emacs mode for Remember The Milk. The code is over on github, and installation is trivial.

Have fun.

Switching identifier naming style between Camel Case and C style in Emacs

There are several naming styles for identifiers used in programming. Some use-dashes-between-words (e.g. Lisp), others MashWordsTogetherAndCapitalizeThem (most often called Camel Case), and a third one puts_underscores_between_characters_and_converts_everything_to_lower_case (sometimes called “C style”).

Often I have to convert code from one naming convention to another. When I have to do that this usually happens with languages that often use both styles, e.g. C/C++ or even PHP and Ruby. For those cases I’ve written an Emacs Lisp function that can convert the identifier at point from C style naming to Camel Case style and back. It detects the current style by looking for an underscore. Here’s the code:

(defun mo-toggle-identifier-naming-style ()
  "Toggles the symbol at point between C-style naming,
e.g. `hello_world_string', and camel case,
e.g. `HelloWorldString'."
  (interactive)
  (let* ((symbol-pos (bounds-of-thing-at-point 'symbol))
         case-fold-search symbol-at-point cstyle regexp func)
    (unless symbol-pos
      (error "No symbol at point"))
    (save-excursion
      (narrow-to-region (car symbol-pos) (cdr symbol-pos))
      (setq cstyle (string-match-p "_" (buffer-string))
            regexp (if cstyle "\\(?:\\_<\\|_\\)\\(\\w\\)" "\\([A-Z]\\)")
            func (if cstyle
                     'capitalize
                   (lambda (s)
                     (concat (if (= (match-beginning 1)
                                    (car symbol-pos))
                                 ""
                               "_")
                             (downcase s)))))
      (goto-char (point-min))
      (while (re-search-forward regexp nil t)
        (replace-match (funcall func (match-string 1))
                       t nil))
      (widen))))

The code was inspired by a question on StackOverflow about this topic.

An interactive, iterative ‘git blame’ mode for Emacs

I’m an active user of Magit for all my Git needs within Emacs. One thing I’ve always found missing was nice support for ‘git blame’ — and by ‘nice’ I mean some more comfort than the simple display of its output.

When I’m hunting bugs one thing I often need is not only the information who modified a certain line but also who modified the line before that. Also what I’d like is having both the source code (including syntax highlighting, of course) and the blame information shown side-by-side with quick access to the log message for particular commits.

That’s what ‘mo-git-blame’ tries to solve. It is a standalone mode that can be used with any of the various Git version control modes. Here are a couple of its features:

  • Shows the output of ‘git blame’ and the file content side-by-side with syntax highlighting for the content
  • Show the log messages for the current revision or the revision in the current line
  • Show the diff (via ‘git show’) for the current revision or the revision in the current line
  • Show the file content for the revision in the current line
  • Call ‘git blame’ for the same file for the revision in the current line

Here’s what it looks like:

Screenshot of Emacs with mo-git-blame-mode

Screenshot of Emacs with mo-git-blame-mode

You can download the sources from my Git repository or directly with

git clone git://github.com/mbunkus/mo-git-blame.git

Installation and usage instructions are included both in the file itself and its README, but here’s the short version:

(add-to-list 'load-path "~/.emacs.d/mo-git-blame")
(autoload 'mo-git-blame-file "mo-git-blame" nil t)
(autoload 'mo-git-blame-current "mo-git-blame" nil t)