It’s not an uncommon occurrence to find yourself editing a file that uses tabs instead of whitespaces, or vice versa. Thankfully, Emacs has facilities in place that make it possible to easily convert between tabs and spaces.
untabify do just that; they convert the region to tabs or whitespaces. When you
tabify, Emacs is smart enough to realign your code, so it should look the same after the replacement has taken place. When you use either command, the variable
tab-width is also used to determine the indentation level.
One important point, though, is that
untabify does not discriminate when it replaces tabs with spaces and vice versa, so that means tabs or whitespaces in strings may suffer. Be careful.
There are several ways of evaluating elisp code in Emacs, and picking the right approach will help you get your job done faster and more efficiently. If you’re new to elisp you will quickly realize that Emacs has many shortcuts and features that makes writing, inspecting or debugging elisp code very easy.
I find prompts in Emacs very annoying and in-my-face, so I have gone out of my way to remove or minimize any interaction I have with them.
Let’s start out by getting rid of the “yes or no” prompt and replace it with “y or n”:
(fset 'yes-or-no-p 'y-or-n-p)
Next up is the annoying confirmation if a file or buffer does not exist when you use
C-x C-f or
(setq confirm-nonexistent-file-or-buffer nil)
If you use ido-mode I recommend disabling the prompt that asks you if you want to create a new buffer if you enter a non-existent buffer in
C-x b. You can replace
never which does the opposite: disables new buffer creation in ido’s switch buffer routine. Setting it to
never is an exceptionally bad idea as creating buffers on-the-fly is a very useful thing to do if you want a quick throw-away buffer.
(setq ido-create-new-buffer 'always)
You can also rid yourself of the splash screen and the echo area message:
(setq inhibit-startup-message t inhibit-startup-echo-area-message t)
And finally, the recently-added prompt in Emacs 23.2 that asks you if you want to kill a buffer with a live process attached to it:
(setq kill-buffer-query-functions (remq 'process-kill-buffer-query-function kill-buffer-query-functions))
If you’re working on a codebase that makes use of CamelCase identifiers
evenWorseLikeThisAbstractFactoryFactory you can make them readable by splitting up the words with
glasses-mode will insert a virtual underscore separator between the conjoined words, so
fooBarBaz will look like
The changes are not permanent and Emacs will keep track of the virtual separators and ensure they are never accidentally saved to disk.
glasses-mode is enabled, you should continue following the CamelCase style as Emacs will automagically insert the virtual separator, as needed, when you type a capitalized character.
There’s a handful of configurable options you can tweak to personalize
glasses-mode. To access them, type
M-x customize-group RET glasses.
Until recently it was impossible to start Emacs in maximized mode in X, but that changed with the release of Emacs 23.2. Now you can force Emacs to start in maximized mode with the command line switch
In Windows you have to use a bit of elisp and Win32 magic to get it to work.
Add this to your .emacs file to make Emacs start in maximized mode in Windows:
(defun maximize-frame () "Maximizes the active frame in Windows" (interactive) ;; Send a `WM_SYSCOMMAND' message to the active frame with the ;; `SC_MAXIMIZE' parameter. (when (eq system-type 'windows-nt) (w32-send-sys-command 61488))) (add-hook 'window-setup-hook 'maximize-frame t)
The code will only execute on Windows, and it works by sending a
WM_SYSCOMMAND window message to itself, telling it to maximize. The magic number
61488 is a constant declared as
By default Emacs will display its tooltips in a separate frame. If you want to force Emacs to use the echo area exclusively, you can do that with this handy code snippet:
(tooltip-mode -1) (setq tooltip-use-echo-area t)
If you’ve ever had to write the word résumé or über or smörgåsbord and, like me, lacked the keyboard character set to do it, you’ve probably reached for an external program to type those characters. That’s completely unnecessary though, as Emacs has complete support for Unicode and has several input methods that makes Emacs act like a bilingual keyboard but without the hassle of having to change your keyboard character set.