This is a read-only archive!

Emacs pain continued

You can make Emacs automatically indent newlines without having to hit tab by putting this in ~/.emacs:

(global-set-key "\\C-m" 'newline-and-indent)

Only took me a half hour to figure that out. I made the mistake of trying C-h a indent (i.e. apropos indent). Emacs gives me no less than 35 results to wade through:

align-newline-and-indent, back-to-indentation, backward-to-indentation, comment-indent, comment-indent-new-line, default-indent-new-line, delete-indentation, forward-to-indentation, indent-according-to-mode, indent-code-rigidly, indent-for-comment, indent-for-tab-command, indent-new-comment-line, indent-pp-sexp, indent-region, indent-relative, indent-relative-maybe, indent-rigidly, indent-sexp, indent-to, indent-to-column, indented-text-mode, inferior-slime-indent-line, lisp-indent-line, move-past-close-and-reindent, newline-and-indent, paragraph-indent-minor-mode, paragraph-indent-text-mode, reindent-then-newline-and-indent, slime-fuzzy-indent-and-complete-symbol, slime-indent-and-complete-symbol, slime-reindent-defun, slime-repl-newline-and-indent, slime-update-indentation, whitespace-toggle-indent-check

(Personally I'm a fan of indent-relative-maybe which sounds like Emacs may indent if it's in the mood but then again don't get your hopes up.)

Of course none of those options tells me how to bind the right function (newline-and-indent in this case) to pressing Enter on my keyboard. But it's nothing massively excessive amounts of googling and reading wiki and blog entries can't solve, I suppose.

Also I found out that one of the reasons my Emacs looked so horrible is that color themes can force-set font faces, overriding my font choices. Particularly, the color theme I was using was making certain bits of text bold, and in spite of my best efforts I found no way to tell Emacs what font I want to use for bold text. Xft fonts in Emacs in general are apparently still experimental and not officially stable, which may have something to do with the difficulty of figuring out how to set fonts. I find this to be a bit behind the times, but I suppose I should feel grateful that Emacs isn't using Motif for its GUI any longer.

I found out today that C-h K will look up what a keybinding does. However it doesn't seem to be able to look up Slime keybindings, only the official Emacs ones in the Emacs manual. I'm still a bit confused about major modes and minor modes and inferior modes, i.e. I have no real clue what the heck those terms mean beyond a vague sense that they set keybindings and maybe syntax highlighting and have some relation to filetypes similar to Vim filetypes. I read as much of the manual as I can but there are only so many hours in a day that one can devote to learning a text editor.

Then there's font-lock, which appears to do something useful because I have it in my .emacs from way back the last time I tried to learn Emacs, but what it does I couldn't tell you (the manual says that "text is fontified as you type it". Fontified? Verbifying nouns doesn't help with my understandingification.) It certainly doesn't lock fonts, whatever that would mean, so I must assume the term "font-lock" is a clever riddle which will lead to Zen-like enlightenment once I figure out its meaning. Well done, Emacs devs.

Is it that Emacs has so many options that the devs ran out of English words and phrases that made sense, and had to start making up gibberish? Or is this simply a secret language that Emacs devotees speak in each other's presence, like a thieves' cant?

November 25, 2007 @ 5:48 PM PST
Cateogory: Programming
Tags: Emacs


Quoth Zeth on November 26, 2007 @ 9:14 AM PST

Font-lock is the older term for syntax highlighting. In my .emacs file is:

(global-font-lock-mode t)

This makes syntax highlighting on by default.

Another way, is when you turn on Emacs you can type

M-x font-lock-fontify-buffer

M = the Alt key

Christopher Giroir
Quoth Christopher Giroir on November 26, 2007 @ 9:16 AM PST

Font-lock is an old term used from back in the day when you did have to do some sort of "locking" on a terminal in order to colorize syntax. It has stuck around like other such things. In emacs >= 22 you don't need to turn global font-lock mode on anymore, it's the default. In 21.4 and below you did need you turn it on (via custimizations or in your .emacs file).

"C-h b" will list keybindings (C-h m like you mentioned in another post is just giving you the info on all of the modes you have enabled, not keybindings unless the mode gives you keybinding information which a lot of them do). C-h b will actually list every keybinding enabled in the current window (be it global keybindings or ANY keybindings from any modes you have enabled).

You can only have ONE major mode on at any time. You can have as many minor-modes as you want. Minor modes often are smaller add-ons that add certain features while major modes shouldn't be used at the same time as another one. The best way to deal with them is to read the manual of the add-on or the readme file. They will tell you the right way to enable or disable the mod (though with gentoo, the ebuilds tell you how to enable all gentoo-installed addons easily).

Inferior modes aren't a full term afaik. It's just the common name for modes that present a shell or repl.

Rebinding return to run newline-and-indent should only be done in modes with hooks. If you do it as a global bind (global-set-key) then other things like the minibuffer that don't have return running kp-enter will not work anymore. I don't have the info offhand about how to do it easily.

Last but not least: for colors I just set up my faces myself. It's not hard to do since most inherit from each other so setting the different faces can be pretty simple. Using "M-x custimize-apropos" then typing "face" you can find many of them. There are also some custimize groups that handle only faces for certain things.

Anyway, enjoy :)

Quoth Zeth on November 26, 2007 @ 9:40 AM PST

Is it that Emacs has so many options that the devs ran out of English words and phrases that made sense, and had to start making up gibberish? Or is this simply a secret language that Emacs devotees speak in each other's presence, like a thieves' cant?

It is more that Emacs in based on 1970s computing terminology. Most other programs today are based on the later IBM terminology that Microsoft and others copied.

So for example, Emacs is Kill and Yank, while IBM is Cut and Paste. Kill and Yank conjure up a more manual age of computing, with vacuum tubes, huge transistors, people plugging and unplugging wire wraps or whatever the heck they had. Whereas Cut and Paste are abstracted metaphorical terms based on a secretary's desk.

Moving on to the 1980s, there was still a wide gulf between Unix users and IBM users, so it did not seem too bad. In the early 1990s, the terminology seemed quaint but understandable.

In text mode at least, Emacs has not changed that much at all in 15 years, however computing culture has changed beyond recognition.

When Emacs first came out, think mainframes with operators and timesharing, etc. Everyone using the computer was an expert.

Now everyone is allowed a computer, no education or training required, and things have dumbed down rather a lot, perhaps too much in some respects, if you think about people who get malware, unwittingly spread viruses or have their unprotected Windows PC become part of a botnet.

I quite like Emacs, as a historical curiosity, it is like driving a classic car.

Quoth Brian on November 26, 2007 @ 12:21 PM PST

Thank you both for the clarifications. It's very helpful.

Ivar Refsdal
Quoth Ivar Refsdal on December 27, 2007 @ 12:37 AM PST

Cheers Brian,

I'm also a newbie at Emacs. Check my blog for some posts about it.

A tip: C-h k (lowercase k) will look up any key combo and give it's function, including Slime keys.

Ivar Refsdal
Quoth Ivar Refsdal on December 27, 2007 @ 1:07 AM PST

Allright. I made it work for me:

(define-key lisp-mode-map (kbd "RET") 'newline-and-indent) (define-key emacs-lisp-mode-map (kbd "RET") 'newline-and-indent)

Quoth Brian on December 30, 2007 @ 1:40 PM PST

Nice blog. I'm enjoying reading it.