Prevent the automatic indent on lines starting with expression - emacs

I'm using emacs, but I'm having a problem with the setting for indents.
Whenever I start a line with #, it automatically indents the line. I don't want this to happen.
Can I configure this behavior? How can I do this?

Each major mode has its own indenting behavior, so in general you need to know which major mode you're using (C-h v major-mode or C-h m), and the way to change the behavior is major mode dependent.
However, I'm going to guess that this is electric-indent-mode (C-h f electric-indent-mode). You can toggle it with M-x electric-indent-mode or M-x electric-indent-local-mode, or customize its variables.

Related

kill-ring-save vs. clipboard-kill-ring-save

In the menu-bar of Emacs-23 under [Edit] there is Cut, Copy, Paste which are all explicit clipboard related commands ; the traditional C-w, M-w, C-y are no longer offered, and these no longer have an effect relevant to X.
What is the cleanest way to make the traditional commands clipboard-aware? It seems there must be some more systematic way than just redefining everything. C-h C-n did not help me.
Is it intended to hide the traditional command from users?
Edit: Or at least: a command to "synchronize" with the clipboard.
X has two "clipboards": the primary selection, and the clipboard. Emacs 23 uses the primary selection by default, but it seems you want the clipboard. You can enable this with the following in your .emacs:
(setq x-select-enable-clipboard t)
This setting changed in Emacs 24 to use the clipboard by default. See also: http://emacswiki.org/emacs/CopyAndPaste

How do I determine why emacs indented a certain amount?

In Emacs I'm editing some source code, and I hit <tab>. Emacs indents the line to n spaces. I'd like to change the amount that indents for that kind of line. How do I figure out what rule emacs applied to indent that line by n spaces?
I want to change n, but I need to figure out which of the many indentation-related variables Emacs just used.
A generic answer is difficult. Some modes will make this more apparent than others, but in the general case (as they are free to implement indentation however they wish) I don't think you'll get away from needing to read some elisp.
Starting with the binding for TAB will work, but might be slightly time-consuming depending on how many layers of indirection are involved.
If you know that the major mode in question implements its own indentation, then one (non-rigorous, but fast) approach that you could try to help track down the functions being called is to use ELP, the built in elisp profiler. elp-instrument-package will instrument for profiling all functions with names matching the prefix string argument you specify. Therefore you might do something like the following in a PHP file (noting that php-mode tells you that it is derived from c-mode)
M-x elp-instrument-package RET php- RET
M-x elp-instrument-package RET c- RET
M-x elp-instrument-package RET indent RET
Now type TAB in your source code, and run M-x elp-results to see which of those instrumented functions were called.
At this point you're on your own -- look for the likely suspects, and see what the code is doing -- but it can be a handy way to filter the search.
Once you've finished, use M-x elp-restore-all to prevent any further profiling.
If you're using a mode based on cc-mode (e.g. c-mode, c++-mode, java-mode, etc.), you can hit C-c C-s and it'll tell you what syntactic category the line is. If you want to change it, hit C-c C-o and you'll be guided through the process. Check out the cc-mode docs on customization for more details: https://www.gnu.org/s/emacs/manual/html_node/ccmode/Customizing-Indentation.html
If you happen to enjoy getting your hands really dirty, there's always the elisp debugger to tell you just what Emacs is up to.
If you hit C-h k TAB you'll find the function that Emacs is running (e.g. indent-for-tab-command) then you can do M-x debug-on-entry RET indent-for-tab-command RET. Now whenever you hit TAB you'll pop up a debugger and can watch the execution step by step.
Depending on your taste for debugging, it's either a maddening or enlightening experience. Either way, don't forget to M-x cancel-debug-on-entry when you're done.

Emacs: setting doc-view-continuous doesn't work with modified key-bindings

I work in Emacs with ergoemacs minor mode turned on. This minor mode changes C-n and C-p to M-k and M-i correspondingly.
In doc-view mode I can move up and down inside one page with M-i and M-k but when the end (beginning) of the page is reached the scrolling stops.
I have set doc-view-continuous variable to t. Here is the result:
continuous scrolling with M-k and M-i doesn't work if ergoemacs minor mode is turned on
continuous scrolling with C-n and C-p works if ergoemacs minor mode is turned off
next page C-x,] and previous page C-x,[ always work
continuous scrolling with mouse wheel always works
PS:
While writing this post I've found out the following:
in doc-view mode C-p is bound to doc-view-previous-line-or-previous-page function which behaves in different ways depending on doc-view-continuous
in doc-view mode + ergoemacs minor mode M-i is bound to image-previous-line function
This difference is the reason of the problem. I will try to use doc-view-mode-hook.
Edited:
Here is the startup code that works for ergoemacs mode:
;; adjust docview mode
(setq doc-view-continuous t)
(defun adjust-doc-view ()
(ergoemacs-local-set-key (kbd "M-i")
'doc-view-previous-line-or-previous-page)
(ergoemacs-local-set-key (kbd "M-k")
'doc-view-next-line-or-next-page)
)
(add-hook 'doc-view-mode-hook 'adjust-doc-view)
The thing I don't understand is why doc-view functions are bound to standard keys but are not bound to ergoemacs keys.
Apparently doc view binds its commands explicitly to C-n and C-p. My guess would be that ergoemacs remaps the usual commands that are bound to those keys, to the keys M-k and M-i instead. Ergoemacs probably does not know about the doc-view commands in question.
Consider filing an enhancement request for ergoemacs, so that it provides a user option whose value is the list of commands to remap this way. That way, instead of doing what you do above, you can just customize the option.
For an example of code that defines such an option, you can refer Xah Lee (author of ergoemacs) to file icicles-opt.el, option icicle-top-level-key-bindings.

Using emacs for coloring display of texts

I have a log file that has a lot of tagging information, i.e, "ERROR", "WARNING", "***". I want to show the log info with different color/fonts based on the tagging info.
How can I do that?
Do I have to come up with my own major/minor modes? Is there some elisp code that I can reuse?
You can do this interactively with:
M-s h r regexp <RET> FACE <RET>
or
C-x w h regexp <RET> FACE <RET>
see the documentation for Interactive Highlighting. Note: The second key binding is only available after you've turned on Hi-Lock mode via M-x global-hi-lock-mode.
If you want to set up a minor mode to do this on a regular basis, I'd check out fixme-mode and modify things from there.
It might be useful to read the Faces portion of the manual to understand what is going on.
Generic Mode was designed to ease the creation of simple custom modes for things like this.
You can use a similar function in hooks for modes you care:
(defun add-watchwords ()
(font-lock-add-keywords
nil '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\):"
1 font-lock-warning-face t))))
I use this for coding modes obviously, so you should adjust the items you want highlighted.

Remove Emacs highlighting

I use the emacs command 'highlight-compare-buffers' to see the changes between two files. But I don't know how to turn the highlighting off. It seems like it should be really easy, but I can't seem to figure out how even with lots of googling and searching the emacs help files.
Try:
C-u -1 M-x highlight-compare-buffers
global-highlight-changes is an
interactive autoloaded Lisp function
in `hilit-chg'.
(global-highlight-changes &optional
arg)
Turn on or off global Highlight
Changes mode.
When called interactively:
if no prefix, toggle global Highlight Changes mode on or off
if called with a positive prefix (or just C-u) turn it on in active mode
if called with a zero prefix turn it on in passive mode
if called with a negative prefix turn it off
I don't have emacs installed on this box, so this is untested, but highlight-changes-toggle-visibility might work.