I want to set the require-final-newline for every buffer to nil.
In my config file, I have :
(setq require-final-newline nil)
(setq-default require-final-newline nil)
It appears to set the global value correctly. However in every buffer that I open, the local value is still t. Using describe-variable, I get :
require-final-newline is a variable defined in `files.el'.
Its value is t
Original value was nil
Local in buffer myfile.js; global value is nil
files.el is in /usr/local/Cellar/emacs/24.5/share/emacs/24.5/lisp/, so I guess I should not modify it.
How do I set this local value to nil ?
Firstly, there are modes which forcibly set require-final-newline on the basis that those kinds of files require a final newline. I don't believe js-mode is one of them, however.
Presumably you have some custom config which is causing this, perhaps set via js-mode-hook or prog-mode-hook.
Confirm with emacs -Q that this is not default behaviour, and then you can set about tracking down the culprit (I would just M-x rgrep for require-final-newline in your elisp files).
Related
In emacs, we can define customizable user option variable.
defcustom - Programming in Emacs Lisp http://www.gnu.org/software/emacs/manual/html_node/eintr/defcustom.html
And we can make variable to have buffer-local binding.
Creating Buffer-Local - GNU Emacs Lisp Reference Manual http://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Buffer_002dLocal.html#Creating-Buffer_002dLocal
If I want to make non-customizable variable, I can use make-local-variable or setq-local.
But I can't find any ways how to make customizable variable to have buffer-local binding.
Even if I call make-local-variable for variable defined by defcustom, custom-set-variables set to global-value.
If I call setq-local, value is set to local-variable. It is better. But I don't think this is best practice.
Is there any valid ways how to set buffer-local value for a variable defined by defcustom?
The answer is: You can't, at least not using the Customize UI.
What you can do is add a sexp that sets the buffer-local value of the variable to your init file.
Do one of the following:
Make it always buffer-local, no matter what the buffer is:
(make-variable-buffer-local 'the-variable)
You can put this anywher in your init file.
Make it buffer-local only for the current buffer, i.e., for some buffer after you select it:
(make-local-variable 'the-variable)
For that, you need to put the sexp in a sexp that selects the buffer you want. That could be, for example:
(with-current-buffer (get-buffer-create "the-buffer-name")
(make-local-variable 'the-variable))
That assumes that the buffer can be reasonably created or already exists. If you do this, do it after your custom-file has been loaded. That is, in your init file, either after loading custom-file (which I recommend) or, if you do not use custom-file, after any code generated automatically by Customize (e.g., custom-set-variables).
You can alternatively put the make-local-variable sexp on a mode hook, so whenever you are in a buffer that has a particular mode, it is executed.
All of that said, I submitted an enhancement request to Emacs Dev in 2012, requesting that user's be able to use the Customize UI to set (and possibly save) buffer-local values of user options. It sleeps in category "wishlist", so far.
After defcustom form write
(make-variable-buffer-local 'my-var)
Now, if you change the value in some buffer, other buffers will keep resp. deliver the old customized one.
The problem is that Customize is mostly designed for persistent configuration, i.e. configuration that is saved in the config file so it also applies to future Emacs sessions. But buffers are not persistent: when you restart Emacs you get a new buffer object.
So persistent customization "per-buffer" is not a clearly defined concept. We could/should add Customize support for settings that are specific to some major modes (i.e. "per-mode" settings), on the other hand.
I have my emacs configuration file under ~/.emacs with just one declaration:
(setq default-directory "/var/www/")
What I want to do is to C-x C-f and go directly to my apache directory. But I tried using C-x C-f and my current directory is HOME.
The file gets loaded, because I used this: (shell) and the shell gets opened. Anyone knows where my error is? I just want to set the start-up directory in htdocs.
default-directory does not do what you seem to think. C-h v
default-directory
default-directory is a variable defined in `buffer.c'.
Its value is "/"
Local in buffer stackoverflow.com/questions/14914353; global value is nil
Automatically becomes buffer-local when set in any fashion.
This variable is safe as a file local variable if its value
satisfies the predicate `stringp'.
Documentation:
Name of default directory of current buffer. Should end with slash.
To interactively change the default directory, use command `cd'.
It's a buffer-local (i.e. buffer specific) variable, meaning its value is
different depending on which buffer is currently active. So when you think you've set it to
"/var/www", you are simply visiting a file already in that directory.
If you want to open a file from "/var/www", you need to make your own command
that binds "/var/www" to default-directory.
Just in case someone is wondering how to do this:
As #Pacha was saying, when emacs starts, the welcome screen shows up and it will change your working directory to the command-line-default-directory
So, for example, If you want your default directory to be "~/", add this to your .emacs and you should be on track.
(setq command-line-default-directory "~/")
(setq default-directory "~/")
Solved it, it was a really weird problem.
Every time I try to open a file from the default buffer (*GNU Emacs*) it changes the default directory to ~/, but when I try to open a file from another buffer, it opens to the one I specified in my variable.
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).
As the title asks, why customize Emacs variable "sgml-xml-mode" (from file "sgml-mode.el")? In "(define-derived-mode sgml-mode text-mode '(sgml-xml-mode "XML" "SGML")" there is the line " (set (make-local-variable 'sgml-xml-mode) (sgml-xml-guess))" which makes that variable buffer local and which uses function "sgml-xml-guess" to give it a value, so what is customizing that variable good for?
For example, creating a buffer "new" and setting its mode to "html-mode" has the result that "sgml-xml-mode" has the local value nil--even if customization sets the global value to t.
The variable is defined thusly:
(defcustom sgml-xml-mode nil
"When non-nil, tag insertion functions will be XML-compliant.
It is set to be buffer-local when the file has
a DOCTYPE or an XML declaration."
:type 'boolean
:version "22.1"
:group 'sgml)
I am using:
GNU Emacs 23.3.1 (i386-mingw-nt5.1.2600) of 2011-03-10 on 3249CTO
A related question is Make emacs always close html tags.
It's just a historical accident. I"m not sure this question is appropriate here, BTW.
I asked a question here, and got good responses, but the problem turned out to be different from what I had thought.
I am trying to assign a certain function to the key "C-c" in shell mode, but it seems that a minor mode called tabbar-mode has a prefix-key assigned to "C-c", which overrides my setting for shell mode. How can I disable tabbar mode key assignments?
I put these after (require 'tabbar), but they did not work:
(defvar tabbar-mode-map nil)
(defvar tabbar-prefix-key nil)
(defvar) only initialises a variable if it has no value. See C-hfdefvarRET for details.
Use (setq) to change the value of an existing variable.
To prevent the mode's keymap from being used when looking up key-bindings, you can delete it from the minor-mode-map-alist variable:
(assq-delete-all 'tabbar-mode minor-mode-map-alist)