I'm using Emacs 23.1 with ESS 5.4 to edit an Sweave file. I'd like to turn off the default AUCTeX indentation behavior in the buffer (to avoid annoyances with code chunks contained in itemized lists), so at the top of the file I have % -*- LaTeX-indent-level: 0; LaTeX-item-indent: 0; -*-. When I open the buffer and run C-h v LaTeX-indent-level, I get what I wanted:
LaTeX-indent-level is a variable defined in `latex.el'.
Its value is 0
Local in buffer test.Rnw; global value is 2
This variable is a file local variable.
However, after I edit a code chunk, it returns to the default behavior. C-h v LaTeX-indent-level now yields:
LaTeX-indent-level is a variable defined in `latex.el'.
Its value is 2
I tried the fix suggested in the noweb-mode FAQ, which suggests adding
(add-hook 'noweb-select-mode-hook
'(lambda () (hack-local-variables-prop-line)))
to my .emacs. The behavior described above persisted when I did this.
Is there any way I can get buffer-local variables to work in this situation? I would prefer not to have to change my .emacs to set LaTeX-indent-level to 0 in all Sweave/noweb buffers.
I haven't tested this, but try the following instead:
(add-hook 'noweb-select-mode-hook
'(lambda () (hack-local-variables)))
Perhaps hack-local-variables-prop-line has been changed to merely parse the values, not instate them.
Related
I recently upgraded Emacs 24.5.1 from 24.1 on my OSX machine. I use the native Cocoa Emacs application.
Since the upgrade, I have been unable to use M-x set-variable to change the value of a variable. The variable is defined in my .emacs with the syntax:
(defvar project-root-directory nil)
With the above definition, after Emacs starts up and the .emacs file is loaded without errors, when I hit M-x set-variable, Emacs complains that project-root-directory variable does not exist.
Did anything change with defvar syntax in Emacs 24.5 that disallows setting a variable using M-x?
The answer to your question is yes, something did change for Emacs 24.5 that broke this feature. More precisely, the breakage was introduced in Emacs 24.3, not 24.5.
Prior to Emacs 24.3 (that is, for decades!), it was enough to just put * as the first character of the doc string, to make a variable into a user variable, so it could be used with set-variable. (The * does not show as part of the displayed doc string.)
In other words, prior to Emacs 24.3, all you needed to do was this, to be able to use M-x set-variable:
(defvar foo 42 "*This is a user variable.")
Was it a good idea for Emacs to drop this feature? Some think so. (I don't.)
What is the current situation?
As #Thomas said, set-variable works for variables that are defined using defcustom. More precisely, however, it is defined for variables for which custom-variable-p returns non-nil.
So you can still use M-x set-variable with a variable that was defined using defvar, provided you give it a non-nil standard-value property (this makes it satisfy custom-variable-p):
(defvar foo 42 "This is a user variable.")
(put 'foo 'standard-value 42)
Your variable should be a user option variable name, i.e., a Lisp variable
meant to be customized by users. Thus, use defcustom instead of defvar:
(defcustom project-root-directory nil
"The root directory of the project.")
You might want to come up with a better documentation string for the variable than the one in this example.
(This was already the case prior to Emacs24.)
In emacs, org-mode has been enabled and have opened some *.org files. Now in the init.el file i am trying to enable the outline-minor-mode in order to fold the lines starting with ";" . When i try to evaluate the (outline-minor-mode) command i get the message "Symbol's function definition is void: th-outline-minor-mode-init"
Seems like the org-mode sets up the outline-minor-mode-hook
outline-minor-mode-hook's value is (th-outline-minor-mode-init)
This variable may be risky if used as a file-local variable.
How to setup the outline-minor-mode for init.el file so that the ";" is treated as heading.
Note:- When emacs is launched with --no-init-file option, outline-minor-mode works for init.el file
Doesn't org-mode use an org- prefix pretty consistently?
On that assumption, th-outline-minor-mode-init doesn't look like an org-mode function to me, so something else is probably at fault, and you'll need to find out what.
Obviously you can't find-function if it's void, so I'd just M-x rgrep your config for th-outline-minor-mode-init (or most likely searching for (add-hook 'outline-minor-mode-hook 'th-outline-minor-mode-init will find the culprit directly).
That issue aside, I happen to use outline-minor-mode in my init file (with headers being lines beginning with ;;;;, and auto-folding the ones beginning with ;;;; *), using the following Local Variables block at the end of the file:
;;; Local Variables:
;;; outline-regexp: ";;;; "
;;; eval:(progn (outline-minor-mode 1) (while (re-search-forward "^;;;; \\* " nil t) (outline-toggle-children)))
;;; End:
I keep a lot of documentation in the file, and with <backtab> bound to outline-toggle-children I find this a pretty convenient way to access it.
Generally, how can I customize the value of a buffer-local variable in Emacs? For example, the variable w3m-lnum-mode is buffer-local, if I set (setq w3m-lnum-mode t) in .emacs, its value in a w3m mode buffer is still nil. How could I set it to t in w3m major mode?
Major modes have a hook variable for this sort of thing. Look for w3m-mode-hook.
(defun my-w3m-hook nil
(setq w3m-lnum-mode t))
(add-hook 'w3m-mode-hook #'my-w3m-hook)
The indirection to hook a separate function is not absolutely necessary, but simplifies the management of the hook functionality (otherwise you'd have to restart Emacs or jump through several hoops to add something to an existing hook; now all you need to do is evaluate a new defun of the function called from the hook).
You can set a default like so:
(setq-default w3m-lnum-mode t)
For fine-grained control, use a hook as RNAer suggests. As far as I can tell though, this is not a normal local variable but a minor mode variable. You actually probably want to do (w3m-lnum-mode 1).
I have an issue using Emacs 24.1.1 on Mac OS X. I'm editing Jade and CoffeeScript files, so I've turned on whitespace-mode for those file types.
What I'm seeing is that lines longer than 70 characters are highlighted with the whitespace-line font face, regardless of the setting of whitespace-line-column.
In this shot, it is clear that I've customized whitespace-line-column to track fill-column, and I've set fill-column to 120, but much shorter lines are being highlighted.
I've glanced over the code for the Jade mode and don't see anything that would explain the behavior, but I have only a passing understanding of Emacs Lisp.
Thanks in advance for any pointers!
You have to set whitespace-line-column before you activate whitespace-mode. That is, if you want to change its value it does not take effect unless you turn whitespace-mode off and on again. Ironically, that variable is not available for M-x customize until you have activated the mode once :-(
However, you can customize the global value of this variable by putting the following line in your .emacs file:
(setq whitespace-line-column 120)
Since your .emacs is evaluated when you start Emacs, the setting will take effect before you invoke whitespace-mode for the first time and should thus do what you want. If you don't want to set the value globally, but only for Jade files, put the following in your .emacs file instead:
(set (make-local-variable 'whitespace-line-column) 80)
(add-hook 'after-change-major-mode-hook
'(lambda () (when (eq major-mode 'jade-mode)
(setq whitespace-line-column 120))))
If you never want long lines to be highlighted specially at all, there is a third option you might want to consider. You could customize the variable whitespace-style (by typing M-x customize-variable ENTER whitespace-style ENTER) and in the value list remove the entries:
lines
lines-tail
(if any). This should turn off highlighting of long lines globally independent of the value of whitespace-line-column (again, only after you de- and re-activate whitespace mode).
This is rather queer. I can't set any value to a variable if it is named 's' in an interactive session:
(setq s 'foo)
=> foo
s
=> nil
Why?
Update 1:
Here is the output from describe-variable on s:
s is void as a variable.
Documentation:
Not documented as a variable.
Why is it that s is kept void in emacs lisp as a global variable?
Update 2:
Turned out, it doesn't happen on a vanilla emacs (meaning one of the modules I load in .emacs or some code in .emacs is causing this).
So the question now is:
What would the original source look like when describe-variable yields "<var> is void as a variable"?
I tried it with setq, defconst, defvar, and defcustom, but none of those produced the message I'm showing.
Update 3:
The message shown above is produced when the variable is literally not bound (though it can be fbound).
(describe-variable 'non-existent)
=> "non-existent is void as a variable.
Documentation:
Not documented as a variable."
So latest question is: Is there any way to prevent a certain variable name
from being bound?
An answer to your revised question:
(defvar s)
The only thing is that this won't let you use describe-variable on it interactively.
(You could then do something like (setplist 's '(variable-documentation "Meh")) to set a description for it without going through defvar.
Just bisect your init file (~/.emacs) recursively until you find the sexp that causes the problem. If it is a sexp that loads another library then either don't use that library or fix it by first finding out what its problem is, the same way: bisect the code in that library recursively, etc.
This is a binary search, and it is very quick. You can quickly comment out half, then 3/4, 7/8, etc. of your file, using M-x comment-region (I bind it to C-x ;). with a prefix arg, comment-region uncomments.
With Emacs 23.1, running the following code makes C-h v s RET show “s is void as a variable.”, but I can't reproduce the inconsistency between setq and retrieving the value of the variable (which I agree is weird).
(setq s t)
(make-local-variable 's)
(makunbound 's)
I suspect an Emacs 24-specific feature or bug.