Why do I start iswitchb-mode this way? - emacs

According to the emacs info page, here's how you enable iswitchb-mode:
To enable Iswitchb mode, type M-x iswitchb-mode, or customize the
variable iswitchb-mode to t
So I put the following in my .emacs:
(setq iswitchb-mode t)
However, this doesn't seem to work. After searching the emacs wiki, I found that I need to use this:
(iswitchb-mode 1)
Could someone explain why I need to enable it this way? I'd like to get a better understanding of elisp rather than just copying and pasting things from places.

Typically a mode will define both a variable and a function with the same name. The function will set the variable properly when it's called, but it's the function that turns on the mode, not just the variable (that only tracks the mode's state).
In your specific case, you were told told customize the variable, but you simply set it instead. The difference is that when the value of the variable changes, custom knows to do something and `setq' knows nothing of this. If you look at the help for this variable (C-h v iswitchb-mode) you'd get:
iswitchb-mode is a variable defined in `iswitchb.el'.
Its value is t
Documentation:
Non-nil if Iswitchb mode is enabled.
See the command `iswitchb-mode' for a description of this minor mode.
Setting this variable directly does not take effect;
either customize it (see the info node `Easy Customization')
or call the function `iswitchb-mode'.
You can customize this variable.

Related

Change default drag-and-drop behavior to open file in read-only mode

I just finished the Emacs Lisp intro and am getting my feet wet with customization. I've browsed the Emacs FAQ, the Emacs W32 FAQ, and perused the fine manual for drag and drop information. I am using GNU Emacs 24.5.1 for Windows without Cygwin (etc.).
I would like to update the default drag and drop behavior to open such files in read only mode. Through C-h f I've identified the dnd functions. In particular, dnd-open-file may be relevant. By C-h k and then dragging a file into Emacs, I've identified the function w32-drag-n-drop. Also, within the Reference Manual is a section on drag-and-drop which specifies x-dnd-types-alist.
How do I identify which of these items, if any, needs to be modified?
What is a safe way to modify its behavior?
I cannot find documentation on x-dnd-types-alist. Is it a function? A variable?
Is there a resource I've overlooked which I should be looking at?
Partial answers of a general nature - I can't help with your dnd problems,
but I hope these suggestions will be of some use.
Q2. It's a good idea to have a minimal init file, containing whatever is necessary to initialize an environment for testing. You can them invoke emacs like this:
emacs -q -l /path/to/minimal/init/file
bypassing your initialization file (-q) and loading the minimal init file instead. Then if something blows up, you just kill this emacs instance, and start again (possibly with a modified init file).
Q3. It's a variable (as are all alists). An alist (short for association list) is a list of key-value pairs. You can get the docstring of any variable with
C-h v VARNAME RET
e.g.
C-h v x-dnd-types-alist RET
Q4. If all else fails, the source is available...

Emacs: setting "comment-column" for all buffers

I am trying to set the comment-column local variable to 70 by default for every buffer I am opening.
I thought that the only thing I had to do is to put the following line in my .emacs file, and to reload Emacs:
(setq-default comment-column 70)
However, when I restart Emacs, it is still to set to 40.
I also tried equivalent like:
(set-default 'comment-column 70)
I am obviously missing something obvious, but I can't find what. I think there is something I don't know about the local variables such as comment-column.
I cite the help on comment-column:
Documentation: Column to indent right-margin comments to. Each mode
may establish a different default value for this variable; you can set
the value for a particular mode using that mode's hook. Comments might
be indented to a different value in order not to go beyond
`comment-fill-column' or in order to align them with surrounding
comments.
Could the bold-faced part be the problem?
I have tried it at my place. There, most programming modes use the global default value whereas modelica-mode uses its own default value.

Call a command with arguments in Emacs minibuffer

I know that M-x (execute-extended-command) allows one to call a command in Emacs by typing its name. That however doesn't allow me to call command with arguments, e.g "backward-word 5"
I am aware that C-5 M-b produces the desired result but I am looking for a general method.
Does anyone know how to do this?
Thanks,
Danny
Eval it: M-: (backward-word 5) RET.
#abo-abo provided the general answer: use M-:.
However, if you are interested not only in obtaining the side effects of the evaluation, and not only in a cursory overview of the return value, but in the full return value (regardless of its size and complexity), then vanilla Emacs M-: is not what you want.
For that, I substitute pp-eval-expression for eval-expression wrt its key bindings (including M-:), and I recommend this practice for others too:
(substitute-key-definition 'eval-expression 'pp-eval-expression global-map)
That pretty-prints the return value, and you can make it print the complete value (no ellipses: ...).
In addition, I offer a modified version of pp-eval-expression in library pp+.el. It has these advantages:
Reads with completion, using pp-read-expression-map.
Emacs-Lisp mode indentation and completion key bindings are available during input.
With a prefix arg, inserts the resulting value into the current buffer at point.
With a negative prefix arg, if the return value is a string, inserts it into the buffer without double-quotes (").
Font-locks the return value (syntax highlighting) for Emacs-Lisp mode. (And during display emacs-lisp-mode-hook and change-major-mode-hook are inhibited.)
Respects new user options pp-eval-expression-print-length,
pp-eval-expression-print-level, and standard option eval-expression-debug-on-error. The former are separate from the similar, standard options eval-expression-print-length and
eval-expression-print-level because the use cases are typically different.
If you use library Icicles then you get the same advantages as library pp+.el -- no need to load pp+.el also.

call emacs commande automatically

I would find a way to execute the commands in the file emacs. Emacs and therefore automatically.
For example I often use: highlight-80
So I'm forced to type every time: Meta key + highlight-80 +-fashion
it's the same with linum-mode and plenty of other.
I have been trying to put in the file emacs.:
(highlight-80 +-mode)
But the option is not enabled.
Thank you in advance for your help. I am looking desperately for a moment, emacs is my working tool quotidient.
Regards
Use C-h f or C-h v, and read the Emacs manual about such choices.
Some of them are user options (variables), whose values you can customize, using M-x customize-option, so the default setting becomes what you want.
Others are modes, which you can call/set in your init file (~/.emacs) --- see the Emacs manual for how to do that. Typically, you use a positive number to turn a mode on and a negative number to turn it off. E.g.: (menu-bar-mode -1) in your init file turns off the use of a menu bar.
In sum, the Emacs manual (C-x r) is your friend. Sit down and have a first chat with it.
You seem generally a bit unsure about how customising Emacs works, so reading the manual on this topic should probably be your next step:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Customization.html
If you are not using the current stable release (Emacs 24.3 at the moment), there's a chance that some of that information will not apply. The in-built manual is, of course, always correct for the version you are running:
C-hig (emacs) Customization RET

How can I filter compilation output only for a specific mode or buffer in Emacs?

I have a HTML page, with html-mode enabled. I call function sgml-validate to check for any markup errors. It's based on compilation-mode. I want to remove some warnings from the compilation output, so I wrote a function and hooked it to compilation-filter-hook (this variable is not documented, but compilation-filter invokes it). Everything works. My problem is that how can I ensure my filter function only gets called when I started the compilation process on a HTML page (via sgml-validate)?
I see two methods, but none of them worked:
First, I can check the value of major-mode. But it always returns compilation-mode, since that is enabled on the *compilation* buffer. (I found a filter function in the source code of grep+, and they did check the value of major-mode. I can't figure out how can it work correctly.)
The other idea was than to only hook my filter function to the HTML file's buffer, but for similar reasons it couldn't work as the output of compilation process goes to a seperate buffer.
It sounds like you can advise smgl-validate so that it performs the filtering before it performs all it's other operations. For example:
(defadvice sgml-validate (around fix-filtering command activate)
(let ((return-value ad-do-it))
(filter-function return-value))))
Meanwhile, I found that compilation-start accepts an optional argument mode, which will be the major mode for the compilation buffer. So I can create a major mode derived from compilation-mode, and define there my filter function now hooked to the proper buffer.
The only problem is now that sgml-validate does not allow me to set the mode argument on compilation-start, but that's another question.
(I don't consider this the ultimate solution, of course.)