2015-01-10 A few random Emacs tips

I’ve quite busy recently, so instead of a full-blown post I’ll share just a few random Emacs tips. Hopefully someone will find them useful.

  1. Don’t know where you can find your init.el? (Or – like me – you want to help some poor Windows guy set up his Emacs?) Try this: C-h v user-init-file.
  2. Do you want to stay in Emacs, even if you accidentally hit C-x C-c (yes, this does happen)? Try putting this in your config: (setq confirm-kill-emacs (quote yes-or-no-p)) (You can also check y-or-n-p and y-or-n-p, or – if you want to be fancy – use a lambda expression to perform partial application on y-or-n-p-with-timeout.
  3. Do you use emacsclient? If yes, you must admit that typing C-x # is a pain in the neck. Why don’t you try (global-set-key (kbd "C-x C-3") 'server-edit)?
  4. Wouldn’t you like AUCTeX’s C-c C-c not to ask whether to save the file you are editing? Put (setq TeX-save-query nil) in your config.
  5. This is trivial, but useful. Let’s create some shortcuts for commands you use often enough to be bothered by their long names, but not often enough to give them keybindings. For instance:
    (defun cal () "Shortcut for CALENDAR (without any argument)" (interactive) (calendar)) (Of course, you can use a more elaborate version to allow for an argument, like M-x calendar does.)
  6. If you happen to create shell (or Perl, or Python) scripts etc. in Emacs, adding this to your init.el might come handy:
(add-hook 'after-save-hook
  'executable-make-buffer-file-executable-if-script-p)

It checks (on saving) whether the file you edit contains a shebang, and if yes, makes it executable.

In fact, there’s nothing here that is not described in the respective manual. You did read them, didn’t you;-)?

CategoryEnglish, CategoryBlog, CategoryEmacs