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.
Related
I would like to have a shortcut that would toggle the showing of line numbers in Emacs.
This is what I have so far:
(defun my-toggle-display-line-numbers-mode-function ()
"Toggles the line numbers"
(interactive)
(display-line-numbers-mode)
)
(global-set-key [(f7)] 'my-toggle-display-line-numbers-mode-function)
But it will only turn on the line numbers. I can't turn it off, unlike when I use M-x display-line-numbers-mode which will turn on or off without any problem.
Any idea how to improve my script so it works as intended?
describe-function (C-h f) on display-line-numbers-mode gives the following:
Signature:
(display-line-numbers-mode &optional ARG)
Documentation:
[...]
This is a minor mode. If called interactively, toggle the
Display-Line-Numbers mode mode. [...]
If called from Lisp, toggle the mode if ARG is toggle. Enable
the mode if ARG is nil, omitted, or is a positive number.
Disable the mode if ARG is a negative number.
This is the automatic desciption produced by the define-minor-mode macro, and for most minor modes, the previous documentation will be exactly the same.
What we get from this:
When called interactively (i.e. as a command, using for example M-x display-line-numbers-mode) this acts as a toggle.
When called from Elisp source code, you need to specify an argument.
If you want it to act as a toggle, use (display-line-numbers-mode 'toggle) in your code. If you want something slightly more advanced than a simple toggle (for example, checking some extra conditions), use 1 and -1 as arguments to respectively enable and disable the mode (incidentally, and although the documentation is unclear, 0 counts as a negative number here, and so (display-line-numbers-mode 0) disables the mode.
As it is often the case, Emacs built-in documentation shows all there is to know. Try to get familiar with the help system, it's really good compared to a lot of softwares.
I'm very new to the Emacs text editor and have just started customizing my ~/.emacs file. I'm wondering if it's possible to change an Emacs setting while it's running. For example, if I put the following in my ~/.emacs file:
(show-paren-mode 1)
I can do the same thing when Emacs is running by typing:
M-x then scroll-step then 1.
Why doesn't this work when I want to do something like this:
(setq scroll-step 1)
When I type:
M-x then setq,
all I get is (no match). There must something I'm not understanding here.
There is a few things:
yes, you can change settings at run-time. If you edit your .emacs file, put your cursor after the closing parenthesis in:
(show-paren-mode 1)
And hit ctrl-x ctrl-e and it will evaluate the code.
some things and variables (though very few) require them to run special things after the setting was changed. Generally there aren't too many and most variables you set will take effect immediately after doing the steps in #1.
However, if you edit your settings using M-x customize you'll find that when you make changes there it'll make the settings active immediately, even in those special cases where something special needs to be done after a value change.
M-x allows you to run "interactive" commands. Some elisp functions are supposed to be called directly by the end user, and others are really only meant when writing elisp into a file. And M-x only lets you easily do the ones that have been marked "interactive". Though M-shift-: will let you type an expression and see the results. EG, try M-shift-: followed by (1+ 2) at the prompt.
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.
I personally keep all lines under 80 characters, but I also work on projects in teams where other programmers don't care about line length.
I love using whitespace-mode, but the long line visualization is really annoying when I'm working on projects where I shouldn't interfere with the long lines. It seems like it should be easy to turn off the long line visualization---I hit m-x global-whitespace-toggle-options l, and then can hit m-x global-whitespace-toggel-options ? to confirm that the "long-line visualization" is turned off. But long lines are still highlighted. I kill buffers and reload them, and highlighting is still there. I'm definitely using global, not local, whitespace-mode.
Why can't I turn off the long line visualization?
The last time I customized whitespace-mode, I noticed that my changes to the settings didn't have any effect in buffers that already existed; try recreating the buffer, or leaving and reentering whitespace-mode. In case you don't already know, you can use M-x customize-group whitespace to turn off that particular option entirely, rather than doing it manually.
Edit: Specifically you want to customize the whitespace-style variable. This lets you turn on and off individual styles. In this case you should turn off the ones labelled "(Face) Lines" and "(Face) Lines, only overlong part". The former changes the face of the whole line when it is overly long, while the latter only changes the face of the part that extends past the threshold.
(Other options in this group define the faces that whitespace-mode will use to highlight the styles you've turned on, the regexes it uses to identify certain situations, etc, but usually you only care about whitespace-style).
Set whitespace-line-column to a higher value (default is 80), so the highlighting of long lines doesn't kick in:
(setq whitespace-line-column 250)
I'm assuming that you already have whitespace-mode activated somewhere in your init.el or similar. If so, you can adapt duma's comment above, and either
Edit the elisp that sets whitespace-style to remove lines-tail. E.g., Emacs Prelude sets
(setq whitespace-style '(face tabs empty trailing lines-tail))
Simply change that to
(setq whitespace-style '(face tabs empty trailing))
If you don't want to directly edit that elisp, but rather override it later with your own code, do something like
(setq whitespace-style (delete 'lines-tail whitespace-style))
Unfortunately, if running Prelude with auto-loaded buffers (using something like Emacs Desktop), the initial setting will take precedence: for each buffer on which you want to see whitespace-style displayed as directed, you must [1]
kill the buffer
re-open the buffer
[1]: Note to OP: if there's another way to reload a buffer, please edit or comment this answer. I was hoping to find something like M-x reload-buffer but am not seeing anything like that with C-h a buffer.
I'm using emacs and auctex to write LaTeX documents. For some reason, M-e doesn't move to the end of the sentence in tex-mode as it did when I went through the tutorial. It moves to the end of the paragraph. (That is, it moves to just before the next double line break)
What is wrong? Do I need to turn on/off some mode to skip to the next full stop? How do I check which modes are active?
I noticed that the same happens in my Emacs. The problem is that the variable sentence-end-double-space is set to t. This means that Emacs expects a sentence to end with a double space. By setting to nil things work properly, i.e., Emacs recognizes a period followed by a single space as the end of sentences.
The first thing to check is what M-e is bound to. In tex-mode, for me, it is bound to forward-sentence. You find this out by C-h k M-e.
It sounds as though it's bound to forward-paragraph, in which case I'd check your .emacs file to see if you've got any overrides in tex-mode hooks, or other things. You can also try running without your .emacs: emacs -q, and seeing what M-e is bound to (to determine if it truly is your .emacs). You can also start without the site lisp file emacs -q --no-site-file - in case your administrators have added anything.