Is it possible not to be asked to save the buffer before compile? - emacs

I'd like to know if there's some way not be prompted with: "Buffer changed, save first? (y or n)" everytime I execute the buffer [C-c C-c] after some change. I came across the variable py-ask-about-save, which has the following documentation:
If not nil, ask about which buffers to save before executing some code.
Otherwise, all modified buffers are saved without asking.
which is a behavior I could accept. However
(setq py-ask-about-save nil)
has no effect. Is there some other thing I should be aware of?
Indeed, it would be even better if C-c C-c had no effect saving any buffer, but only be responsible for executing the code.

The variable py-prompt-on-changed-p appears to be what the O.P. is seeking. The doc-string states:
When called interactively, ask for save before a changed buffer is sent to interpreter.
See also line 10284: http://bazaar.launchpad.net/~python-mode-devs/python-mode/python-mode/view/head:/python-mode.el

Related

Avoid accidental execution in comint mode

Sometimes when in comint mode the point is anywhere in the buffer and I press Return by mistake. This sends the text at point to the underlying process, which can be really dangerous. Often this text contains many lines and, by chance or not, one of them could be a valid command.
Is there any way to tell comint not to execute anything on Return except the last input?
The documented way seems to be override comint-get-old-input variable with a custom function. Easiest will be something like this:
(setq comint-get-old-input (lambda () (end-of-buffer) (comint-get-old-input-default)))
It goes to the end of buffer first, and only then calls coming-get-olt-input-default, effectively not messing with the previous output. Put it in your init.el, brief testing shows that it works.

Emacs buffer undo limit

I get this warning in my matlab-shell buffer when I print alot to stdout:
Warning (undo): Buffer `*MATLAB*' undo info was 12268000 bytes long.
The undo info was discarded because it exceeded `undo-outer-limit'.
This is normal if you executed a command that made a huge change
to the buffer. In that case, to prevent similar problems in the
future, set `undo-outer-limit' to a value that is large enough to
cover the maximum size of normal changes you expect a single
command to make, but not so large that it might exceed the
maximum memory allotted to Emacs.
My emacs looks like this:
I really don't need any undo in the matlab-shell which is the right buffer. Is there a way to disable this warning? Note that the left buffer is a MATLAB script which means that the major mode is MATLAB, and certainly undo should not be disabled there.
As that warning message says (or used to say?):
You can disable the popping up of this buffer by adding the entry
(undo discard-info) to the user option warning-suppress-types,
which is defined in the warnings library.
That is:
(add-to-list 'warning-suppress-types '(undo discard-info))
(That will of course just disable the warning, not the undo data collection itself.)
Your question is a little ambiguous, but assuming you're saying that you have no need to undo things in this buffer, then you can disable the undo system on a per-buffer basis:
buffer-disable-undo is an interactive compiled Lisp function in `simple.el'.
(buffer-disable-undo &optional BUFFER)
Make BUFFER stop keeping undo information.
No argument or nil as argument means do this for the current buffer.
So you can call M-x buffer-disable-undo RET interactively, or if you're sure about it, you could add this to a hook function for the mode in question.
Edit:
So based on the extra information in the question comments, I would suggest this:
(add-hook 'matlab-shell-mode-hook 'buffer-disable-undo)

Emacs Buffer Management

I was wondering how people manage with the useless messages etc emacs buffers generated randomly, for example after my completions, I get an completions buffer and it upsets me it create a buffer I have to traverse to get to the next buffer. Anyone have a solution to this?
The title is rather vague. There are lots of Q&As on the general subject of "buffer management" in Emacs. Here's one which includes links to several others (see "Linked" in the right-hand sidebar):
How can I more easily switch between buffers in Emacs?
For your specific question, I suggest using the excellent winner-mode. Just add (winner-mode 1) to your .emacs file (or type M-x winner-mode RET to try it out).
Once enabled, you can call winner-undo with C-c<left> (repeatedly, if necessary) to step backwards through all the previous window configurations.
Thus, when a window pops up and you no longer want it, you type C-c<left> and you're immediately back to how things were before.
C-c<right> calls winner-redo which restores the configuration you started with (i.e. it doesn't step through the configurations like the undo command).
Also note that many types of buffer can be buried with q or deleted with z.

How do I encourage emacs to follow the compilation buffer

Occasionally when I'm compiling, I have to scroll up my compilation buffer to see the details of an error. At this point, emacs stops "following" my compilation buffer, i.e., scrolling to automatically display new output.
I'm using Aqumacs on OS X. Any idea how I can "reattach" or re encourage the compilation buffer to follow again?
Regards,
Chris
Put in your ~/.emacs file
;; Compilation output
(setq compilation-scroll-output t)
or even
(setq compilation-scroll-output 'first-error)
to make it scroll to the first error.
Try using M-x auto-revert-tail-mode or M-x auto-revert-mode. Taken from official documentation:
One use of Auto-Revert mode is to
“tail” a file such as a system log, so
that changes made to that file by
other programs are continuously
displayed. To do this, just move the
point to the end of the buffer, and it
will stay there as the file contents
change. However, if you are sure that
the file will only change by growing
at the end, use Auto-Revert Tail mode
instead (auto-revert-tail-mode). It is
more efficient for this. Auto-Revert
Tail mode works also for remote files.
So, as Chmouel already noted, just moving point to end of buffer will also work.
I am not sure about aquamacs but for me (Emacs 23/Debian) I just go in the compilation window and place my cursor at the end of the window which will attach and follow (you can go to another window and it will still follow).

Highlight buffer modifications

It often occurs that a file buffer is modified (duh!). Before exiting, emacs asks whether to save the changes. Now it would be interesting to know what actually changed. Is there a way to find out?
As of Emacs 22.1 (at least), 'save-buffers-kill-emacs (the default binding for C-x C-c) prompts you for each unsaved buffer that has a file. Type a d when prompted to save and see the diff.
From the help documentation:
Save some modified file-visiting buffers. Asks user about each one.
You can answer `y' to save, `n' not to save, `C-r' to look at the
buffer in question with `view-buffer' before deciding or `d' to
view the differences using `diff-buffer-with-file'.
If you look at the prompt, it should say something like:
Save file /path/to/file.txt? (y, n, !, ., q, C-r, d, or C-h)
Typing C-h gives you a little more verbose description (but d is what you are asking for):
Type SPC or `y' to save the current buffer;
DEL or `n' to skip the current buffer;
RET or `q' to give up on the save (skip all remaining buffers);
C-g to quit (cancel the whole command);
! to save all remaining buffers;
C-r to view this buffer;
d to view changes in this buffer;
or . (period) to save the current buffer and exit.
I use diff-buffer-with-file, and select the file that the buffer came from (which is the default anyway for the command... just hit enter).
You can also use highlight-changes-mode, though this won't track changes until you turn it on, so not so useful if you want to see what changed when you're closing a file that has not been in this mode :-)
You can have highlight-changes-mode enabled. It will display all changes in red. However it won't show you whitespace changes and will mark removals only with an red _. See also http://www.emacswiki.org/emacs/TrackChanges.
I found this post about tracking changes by djcb most helpful regarding tracking changes in Emacs. The trick is to add the following to your .emacs:
;; higlight changes in documents
(global-highlight-changes-mode t)
(setq highlight-changes-visibility-initial-state nil); initially hide
and then toggle highlight-changes-visible-mode when you want to see what has changed.
In this case I type undo to see the last change (usually some stray character which got typed in the wrong window, since I save early and often).
It would be nice if there were some other indication of the current changes, e.g. in the border like quick diff in Eclipse text editors.
I use goto-chg for things like that. It's not perfect, but it always is enough to jog my memory about what change I made and promptly forgot about.