Notify out-of-date buffers in the mode-line - emacs

Sometimes I use an alternative method (usually sed) to edit a file
that's already being edited by Emacs. Later, if I try to edit the file
in Emacs without reverting the changes first, I get an error message
and a prompt asking me what to do.
That's all fine. The problem is that I tend to forget very often when
I've made some parallel changes, so I'd like Emacs to
remind me by showing a red "M" in the mode-line.
I know how to customize the mode-line (by adding strings to the
mode-line-format variable), but I have no idea how to check if a
file has been modified outside of Emacs.
Is there a function to check whether an Emacs buffer is up to date
with the file it corresponds?

Try
(verify-visited-file-modtime (current-buffer))
See Section 27.6 Buffer Modification Time.

Not really a direct answer to the question, but you can avoid this problem by turning on auto-revert globally in emacs with (global-auto-revert-mode t).

Related

Emacs - suppress Completion Buffer

In Emacs, I don't want the *Completions* buffer to pop up, even when I press tab to autocomplete in the minibuffer and there are multiple results.
It's distracting and jarring.
How can I do this?
Even better, I would like an alternative that isn't distracting or jarring -- such as requiring one tab for autocomplete if available, but requiring two tabs to open a Completions buffer. This way, I don't get the Completions buffer when I'm expecting an autocomplete. This is what the OS X terminal does to show tab completion possibilities.
I think the cause is the minibuffer-completion-help command, which is run automatically, described here: https://www.gnu.org/software/emacs/manual/html_node/elisp/Completion-Commands.html
I use ido and smex, but the problem occurs in a vanilla Emacs too.
EDIT: I found a hack to fix this. Using M-x find-function, I found and copied the function definition of minibuffer-completion-help into my .emacs.d/init.el file. Then, I renamed the version I copied my-minibuffer-completion-help and changed (with-displayed-buffer-window *Completions* to '(with-displayed-buffer-window *Completions* (putting a quote in front so it is just interpreted as a string. Finally, I overrode the call to minibuffer-completion-help by putting
(advice-add 'minibuffer-completion-help
:override #'my-minibuffer-completion-help)
after the my-minibuffer-completion-help function in my .emacs.d/init.el file. There must be a better way.
EDIT 2: quoting out (message "Making completion list...") in my-minibuffer-completion-help has the added benefit of getting rid of the flicker in autocomplete that is caused by flashing another message during autocomplete. Is it possible to do this another way?
I believe you just want to set completion-auto-help to nil:
(setq completion-auto-help nil)
I believe what you're looking for is either temporarily modifying display-buffer-alist, probably setting it to use display-buffer-no-window for *Completions* or M-x customize-group completion and setting Completion Show Help to nil

emacs doremi: to change color-themes

I'm trying to get doremi working in emacs. Specifically, at this stage, to allow me to quickly scroll through a condensed list of color-themes and see each theme as I go through it. For this I would use the 'M-x doremi-color-themes+' command.
What I've done:
Installed color-themes (successfull)
Installed doremi.el, doremi-cmd.el, ring+.el and added
(add-to-list 'loadpath "~/elisp/themes")
(add-to-list 'loadpath "~/elisp/doremi/")
(require 'color-theme)
(color-theme-initialize)
(color-theme-classic)
;; create a list of color themes to scroll through using 'doremi-cmd
(setq my-color-themes (list 'color-theme-classic
'color-theme-retro-green
'color-theme-gray30
'color-theme-subtle-hacker
'color-theme-jonadabian-slate))
(require 'doremi)
(require 'doremi-cmd)
(require 'ring+)
to the .emacs file.
What emacs does:
When I type the comand 'M-x doremi-color-themes+' into the mini-buffer it seems to accept that I've given it a valid command and tells me to use the and arrow keys to move through the list. But when I do that all that happens is the cursor moves up and down in the active window. No changing of color-themes.
Being somewhat new to emacs (and especially customising it) I'm sure I have missed a step or put something in the wrong place. Perhaps there's some sort of (setq 'bla-bla-bla (...)) I need to do?
Sorry for your trouble. Please state your Emacs version (M-x emacs-version), and your version of color-theme.el.
You do not need to require library ring+.el if you use Emacs 23 or later (its code was included in GnuEmacs 23.)
You do not need to use (color-theme-initialize) or (color-theme-classic). The former is done automatically by doremi-color-themes+.
Try starting from emacs -Q (i.e., no init file, ~/.emacs), to be sure there is no interference from stuff in your init file.
Your variable my-color-themes is not referenced anywhere. Instead of defining that variable, just customize user option doremi-color-themes. (Or leave its value nil, which means that all color themes will be cycled through.)
Feel free to contact me by email if you continue to have a problem. Or continue here, if you prefer.
[Just to be sure: you are using color-theme.el, right? There is a lot of confusion out there between Emacs "custom themes" and color themes. Do Re Mi supports both, but they are different critters.]
After a bit for back and forth with #Drew we found a solution to the problem.
It turned out the major problem was that I was using emacs in 'terminal mode' rather than as a GUI application. Bare in mind I'm using a mac.
In the context of Terminal, my arrow keys send escape sequences and so doremi cannot read the event as intended. So it just escapes and applies the message to the active buffer.
There is an answer.
By adding the following lines to my .emacs file (or whatever your init file for emacs is) I was able to redirect doremi to use two other keys. ie. not the up and down arrows.
(setq doremi-down-keys '(?n))
(setq doremi-up-keys '(?p))
Doing this tells doremi to use 'n' as the down key and 'p' as the up key. And all works just fine.
Because I am only new to the world of programming and computing I may often use incorrect terminology. If this is the case please let me know and I will edit accordingly for clarity and consistency.

How to open an org-mode file automatically in Emacs

How to open files automatically when starting emacs? does not work either under Windows or under Linux.
After adding the find-file command I received a message
so I disabled the auto-save, but the file does not load anyway.
(add-to-list 'load-path "~/emacs/org-8.0.3")
(setq auto-save-default nil)
(find-file "/home/uwe/Dropbox/orgmode.org")
You probably want to set the initial-buffer-choice variable so that it switches to your org file after running your init.el.
(setq
org-default-notes-file "/home/uwe/Dropbox/orgmode.org"
initial-buffer-choice org-default-notes-file)
The message you see proves that the file is indeed loaded just fine. All it tells you is that there's some auto-save file left over, indicating that some edits were not saved last time. You can ignore the message (which is not an error message), or you can use M-x recover-this-file RET to recover the unsaved changes from the auto-save file.
I strongly recommend you don't disable auto-saving.
IOW what you think doesn't work (automatically loading orgmode.org) actually does work. The only thing that doesn't work the way you want is that this file is not displayed and instead the *scratch* buffer is displayed. The reason for this depends on how you started Emacs. And the fix for it depends on all the different ways you might start Emacs (e.g. if you only ever start Emacs in the exact same way, it's easier).
Don't disable the auto-save, it could save ours files.
Anyway, delete #orgmode.org, if the diff between the two file don't interest you.

Emacs dired: too much information

I'm trying to use Emacs and everything is fine, but the information about every file in my directory is too comprehensive. How can I tell it to show only file name (and maybe filesize in human readable format)? I tried options like dired-listing-switches but without any luck.
As of Emacs 24.4, hit key (.
Repeated, this will hide/unhide details. This is part of Dired Details.
You can reduce the amount of information displayed by using Emacs' ls emulation instead of allowing it to use ls directly.
To enable ls emulation, add the following code to your startup file (probably .emacs or .emacs.d/init.el):
(require 'ls-lisp)
(setq ls-lisp-use-insert-directory-program nil)
You can then customise the display with M-x customize-group RET ls-lisp RET. Specifically, the "Ls Lisp Verbosity" setting can be used to disable a number of columns. There's no obvious way to get it down to just the filename and size, but you can certainly get rid of the owner/group/link-count columns.
Great news, a more efficient version of DiredDetails is in the master branch of Emacs now; it uses text properties instead of overlays..
I looked for it because DiredDetails' reliance on overlays made it too slow for one find-dired result set.
I'm not sure if it'll be in 24.3 or 24.4. Get the raw file here: http://git.savannah.gnu.org/cgit/emacs.git/plain/lisp/dired.el
also, to show file sizes in human-readable format (kB/MB), add this to your .emacs:
(setq-default dired-listing-switches "-alh")

how do I disable Flyspell?

It sounds easy but I can't fix it: I want to permanently disable automatic spell-checking in emacs. There must be a simple line for my init.el. Can somebody help me?
Figure out why it's on in the first place (it isn't enabled by default), then fix that. Either your init file is turning it on, or else some system-wide init file is. Read about those files: http://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html
From a brief look, the simplest way I can see is to redefine the function:
(eval-after-load "flyspell"
'(defun flyspell-mode (&optional arg)))
or you could use advice to force the argument to always be -1 (see C-h f turn-off-flyspell), but that would be slightly more complex and less efficient for no good reason.
If you want to know what is running it in the first place, you could use M-x debug-on-entry flyspell-mode, which will show a stack trace when the function is called (q to exit the debugger; C-h m to list other commands; M-: (info "(elisp)debugger") for help). Use M-x cancel-debug-on-entry to remove that breakpoint.
(flyspell-mode 0)
I found mine in ~/.emacs.d/usk/text.el
I deleted the block of code having to do with FlySpell and closed emacs.
After reopening emacs, I still saw the spelling error (red underline). However, I simply deleted and retyped the "misspelled" words and then, emacs didn't underline. Problem solved.
I'm running Debian.
In my case flyspell-mode has been gaining ground in the .emacs.desktop file.
This was not the first time that desktop-mode causes pain in restoring obsolete things. In this case it restored all modes on a per-file basis, although in .emacs.el I had already disabled flyspell-mode and flyspell-prog-mode everywhere.
Solution: either edit the .emacs.desktop file or delete it.
Using Emacs graphical mode you can just right click above "Fly" minor mode bellow and select "Turn Off minor mode" like this: