Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the Emacs fill-column for a specific mode?

I would like to set the fill-column in Emacs to 120 for Clojure-mode, but leave it at the default (80) otherwise.

How can I do this in my .emacs file?

Thanks.

like image 838
Ralph Avatar asked Nov 10 '11 13:11

Ralph


People also ask

What is fill column indicator?

The fill-column indicator is a useful functionality especially in prog-mode and its descendants (see Major Modes) to indicate the position of a specific column that has some special meaning for formatting the source code of a program.

What is fill paragraph?

The command M-q ( fill-paragraph ) fills the current paragraph. It redistributes the line breaks within the paragraph, and deletes any excess space and tab characters occurring within the paragraph, in such a way that the lines end up fitting within a certain maximum width.

How do I show columns in Emacs?

If you prefer menu-based customization, select Options > Show/Hide > Column Numbers, then Options > Save Options. (This might vary depending on Emacs version.) I'm not into the menu-bar, if you are't either you can do M-x customize-variable then put in column-number-mode then you can toggle the mode on or off.


2 Answers

Add a call to set-fill-column to the clojure-mode-hook.

(add-hook 'clojure-mode-hook
          (lambda ()
            (set-fill-column 120)))

As fill-column is buffer local, it won't affect other buffers. In fact, you can invoke M-x set-fill-column RET 120 to set the fill column in any Emacs buffer interactively.

You can check if a variable is buffer local by invoking the help: C-h v fill-column specifies:

Automatically becomes buffer-local when set in any fashion.

like image 87
Antoine Avatar answered Oct 17 '22 00:10

Antoine


fill-column is a buffer-local variable, i.e. it can have unique value in each buffer (if you want). So you can just set it in clojure-mode hook.

like image 42
Dan Kruchinin Avatar answered Oct 17 '22 01:10

Dan Kruchinin