Though I mostly hate auto-fill-mode, Org Mode makes a good case for using it, so I don't want to disable it for Org Mode by default. However, I do have some Org files where I absolutely do not want it, and am sick of typing M-x auto-etc every time I open them.
I know you can pass variable to Emacs from file headers, and after a bit of searching I came up with this document from which I deduced that I want something like this:
-*- mode: Org; auto-fill-mode 0 -*-
as the first line of my file. But not this exactly, because that gives me an error:
Malformed mode-line: "auto-fill-mode 0"
and auto-fill mode does not start up.
I am sure it is a simple error in syntax, but it would be nice to know the right way to do this.
This is what I use:
# -*- mode: Org; eval: (auto-fill-mode 0) -*- #
Note that the # characters are optional, I just prefer them for style reasons.
$ info emacs
48.2.4.1 Specifying File Variables:
Do not use the `mode' keyword for minor modes. To enable or disable
a minor mode in a local variables list, use the `eval' keyword with a
Lisp expression that runs the mode command (*note Minor Modes::).`
As per this part of the doc, append this to the end of your file:
# Local Variables:
# eval: (auto-fill-mode 0)
# End:
You are missing a colon:
-*- mode: Org; auto-fill-mode: 0; -*-
Related
I'm trying to enable whitespace mode but it doesn't seem to be working for me.
I've added the whitespace.el file to my .emacs.d/ directory.
I added the following lines to me .emacs file:
(add-hook 'before-save-hook 'whitespace-cleanup)
(add-hook 'before-save-hook (lambda() (delete-trailing-whitespace)))
(require 'whitespace)
I did the following in the whitespace.el file:
M-x byte-compile-file <path to whitespace.el>
I tried executing the following command from any random text in emacs (e.g.: test.c):
M-x whitespace-toggle-options RET
But I just get a message saying [No match]
What am I missing?
Also, will I have to type in a command to enable the whitespace-mode every time I use emacs?
whitespace.el has been included in Emacs for quite a while. Unless you have a very old version, you shouldn't need to manually put it anywhere, or do anything particularly special to use it.
whitespace-toggle-options probably isn't the function you want to use. Instead, try whitespace-mode:
Toggle whitespace visualization (Whitespace mode).
With a prefix argument ARG, enable Whitespace mode if ARG is
positive, and disable it otherwise. If called from Lisp, enable
the mode if ARG is omitted or nil.
If you want to enable it by default, add
(global-whitespace-mode)
to your init file.
I am trying to create a yasnippet for new projects in org-mode.
The beginning of the yasnippet looks like this.
# -*- mode: snippet -*-
# name: project
# key: project
# --
#+TAGS: project(p)
* $1
* $2 :project:
However, I have the following problem on the line with the :project: tag.
The input is input with large spaces between each letter. Is this a problem in org-mode or does the org-mode syntax for tags represent something in yasnippet definitions?
!
Emacs doesn't recognize the extension .hgrc, so it uses fundamental mode and all the text is black, including comments. Is there a good mode to use for editing .hgrc? And how would I configure emacs to use that mode automatically when I'm editing .hgrc?
Learned so far from answers:
conf-mode is the mode I want, and there are various ways to configure emacs to use it for editing .hgrc.
I added
(add-to-list 'auto-mode-alist '("/\\.[^/]*rc" . conf-mode) t)
to my .emacs.el, so
my emacs opens all RC files (including .hgrc) in Conf[Unix] mode.
The reason for the 3rd argument to add-to-list is that the default mode for run control files is conf-mode unless a prior setting overrides it.
Visit .hgrc, switch to Conf Mode with M-x conf-mode, and then type M-x add-file-local-variable-prop-line RET mode RET conf-mode.
This adds a special comment at the beginning of your .hgrc, which tells Emacs to use conf-mode for this file:
# -*- mode: conf; -*-
[extensions]
hgext.color =
# …
Surprisingly file .bashrc_custom has Fundamental mode even though files .bashrc and .bash_profile in the same directory have (Shell-script[bash]).
How can I configure major mode for .bashrc_custom?
Put this into your Emacs init file:
(add-to-list 'auto-mode-alist '("\\.bashrc_custom\\'" . sh-mode))
Note possibly directory local variables are not questioned here, it's ruled by a list reading strings resp. regular expressions for matching file-names.
So (let us not concern ourselves with why) I have a .emacs file which is called dotemacs, and a .bashrc file which is called dotbashrc.
When I load up dotemacs, I get no syntax highlighing (amongst other things). If I do M-x lisp-mode then all is well.
Without changing the name of the file, how do I get emacs to recognise automatically that dotemacs is a lisp file and go into lisp-mode? Similarly for bash scripts, and indeed any other type of file with the wrong (or no) extension.
You can put this at the top of the dotemacs file:
; -*- mode: lisp -*-
causing it to start elisp-mode when you load the file.
For shell scripts, putting a #!/bin/bash (for whichever shell you are using) is enough to turn on the correct mode. Or otherwise put this at the top of the file:
# -*- mode: sh -*-
I like the answer above, but here is another way you could do it :)
Add the following line to your .emacs
(add-to-list 'auto-mode-alist '(".emacs" . lisp-mode))