emacs: force ido-mode to forget history - emacs

I wonder if I can keep ido from not remembering my history and only show completions for files that are in the current directory when I am searching for a file. I understand that this history feature is useful at times, but I often end up editing the incorrect file because I think I am editing file called 'abc.txt' in the current directory but in fact I am editing the file by the same name in another one that I previously visited (often happens when there is not an 'abc.txt' in the current directory, as I mistakenly assume). From reading the ido.el file I thought to set in my .emacs file (also evaluated these expressions in running emacs instance):
(custom-set-variables
'(ido-enable-last-directory-history nil)
'(ido-record-commands nil)
)
and deleted a file called .ido.last in ~/, but still it remembers some previous files I've visited before making these changes. How can I purge my previous history, and I am not entirely sure what the difference between the two variables above are but seems to have done the trick to keep ido from remembering files I visit in the future?
Thanks for your help!

Deleting ~/.ido.last and setting the variables as above appears to keep ido from searching files visited in the past.
Edit: Actually, the full customization for this task would be
(custom-set-variables
'(ido-enable-last-directory-history nil)
'(ido-record-commands nil)
'(ido-max-work-directory-list 0)
'(ido-max-work-file-list 0))

This happens to me all the time. Given I am in directory /path/to/dir and I try to edit abc.txt, (ido-find-file) will "helpfully" pop me over to /somewhere/else/abc.txt if /path/to/dir/abc.txt doesn't exist and /somewhere/else/abc.txt does.
In this situtation, CTRL-F in the minibuffer when in the middle of an (ido-find-file) reverts to the usual behavior of (find-file), so I can force Emacs to edit /path/to/dir/abc.txt, dammit.

Setting ido-auto-merge-work-directories-length to -1 disables automatic directory switching.

Related

How to ignore emacs temp files in Jekyll?

I have Jekyll blog and when I run jekyll serve, and I'm editing the post in GNU Emacs I got this output:
Regenerating: 2 file(s) changed at 2020-02-28 09:05:34
_posts/2018-10-20-pytania-rekrutacyjne-css.markdown
_posts/.#2018-10-20-pytania-rekrutacyjne-css.markdown
...done in 13.517243884 seconds.
is it possible to ignore files that starts with .#. I assume it would be twice as fast to generate the html page.
I've tried this:
exclude:
-
README.md
-
.\#*
-
_posts/.\#*
but this don't work, it regenerate when I save _config.yml (as .#_config.yml) the same as with posts.
I would like to ignore every Emacs file in my Jekyll project.
Files with a .# prefix are lockfiles. They prevent separate Emacs instances from editing the same file at the same time. See https://www.gnu.org/software/emacs/manual/html_node/emacs/Interlocking.html. Personally, I set (setq create-lockfiles nil) because I rarely run more than one Emacs, and I have (global-auto-revert-mode 1). auto-revert-mode will watch for a file to be changed and automatically reload it (or tell you it has changed if there are unsaved changes).
Also take a look at https://github.com/emacscollective/no-littering to move autosave and backup files to a common place instead of next to whatever file you're editing.
Probably only the message is confusing. It says 2 files changed, which is correct. It does not say 2 files regenerated. My config does not even exclude .#-files. I get the same message, but no .#-file is generated. Check the _site folder. And check the time to regenerate the output file
touch _posts/2018-10-20-pytania-rekrutacyjne-css.markdown # still around 14 sec?
touch _posts/.#2018-10-20-pytania-rekrutacyjne-css.markdown # should be close to zero?

Force DocView mode to show updated file without confirmation?

I use DocView Mode to display .pdf compilations via "latex-preview-pane-mode." Recently, Emacs will ask me "file ____.pdf changed on disk. Reread from disk? (yes or no)".
Typing "yes" each time disrupts my workflow. I have tried setting auto-revert-mode for the DocView buffer, but this did not help. Is there any way to fix this, or any idea why it changed suddenly (no changes to my .emacs.d in the recent past).
To achieve what Tristan suggests, first I tried M-x customize-variable RET revert-without-query, but couldn't get very far, so I wrote this in my init.el file:
(setq revert-without-query '(".pdf"))
and I'm happily udating my pdf files from org-mode without getting queried every time. (I use pdf-tools).
Source: fourth answer to a similar question in stackoverflow
(defun revert-buffer-no-confirm ()
"Revert buffer without confirmation."
(interactive)
(revert-buffer :ignore-auto :noconfirm))
Source: http://www.emacswiki.org/emacs-en/download/misc-cmds.el
Maybe this function could help you out
Take a look at the variable revert-without-query. From the Emacs Lisp documentation:
This variable holds a list of files that should be reverted without
query. The value is a list of regular expressions. If the visited
file name matches one of these regular expressions, and the file
has changed on disk but the buffer is not modified, then
‘revert-buffer’ reverts the file without asking the user for
confirmation.
Adding .+\.pdf to the list should make buffers visiting pdf files revert when you change the file on disk.

What "local rules" have been set in Emacs?

I have been trying to solve a sh-mode indentation issue in Emacs (I get a double indent after a then) and found that I can set the indentation by hand and then run C-c > to automatically configure the indentation.
However, this configuration only applies to my current session and I can't seem to find any variables that have been modified as a result of the auto-configuration. (It worked though: the indentation is consistently what I want.) When it has run, it says "Local rules set" but doesn't tell me what local rules have been set.
And of course, when I restart Emacs, the local configuration is lost and I have to run the auto-config command again.
I've found a number of questions on this site about listing variables and their values, but I can't find out how to list ones that have only been changed for the current session. I even used this post to dump variables before and after running the C-c > command and comparing the output; nothing obviously different.
So I suppose my question is twofold:
If session variables are what's meant by "local rules" then how do I find out which ones were set?
If "local rules" means something else, then what is that and how can I somehow transfer those changes to my ~/.emacs file?
I think the result depends on your version of Emacs, but with a recent version, this is handled by SMIE, so the personal settings are kept in the smie-config variable.
The local settings in use in the current buffer are kept in an internal variable (smie-config--buffer-local). You can move them over to smie-config and save them into your ~/.emacs by calling smie-config-save.
One more detail: smie-config-save doesn't in itself save the settings to ~/.emacs. It only transfers them from the transient buffer-local variable smie-config--buffer-local to the global smie-config variable which is under the control of Customize and can have be saved to your ~/.emacs via something like M-x customize-save-customized. This should arguably be improved in smie-config-save. I suggest M-x report-emacs-bug to ask for this improvement.
This is more of an incomplete workaround than an answer, but it's a start!
The idea is to trigger sh-learn-buffer-indent as soon as a shell script is loaded. Add the following to your ~/.emacs file:
(add-hook 'sh-set-shell-hook 'sh-learn-buffer-indent)
A couple of important notes:
It assumes that your shell script is already correctly formatted when it's loaded.
It can be slow for large files.
(This is apparently mentioned in sh-script.el and was brought to my attention by Noam Postavsky via the bug report I filed.)

Is it possible to prevent emacs from creating " .#files " [duplicate]

When I modify a buffer, Emacs automatically creates a temporary symlink in the same directory as the file being edited (e.g. foo.c):
.#foo.c -> user#host.12345:1296583136
where '12345' is Emacs' PID (I don't know what the last number means).
Why does Emacs create these links, and how do I prevent it from doing that?
Note that I have turned off auto save mode (M-x auto-save-mode) and disabled backup files (M-x set-variable -> make-backup-files -> nil). When I save a modified buffer, or undo the changes to it, the symlink disappears.
In particular, I'm trying to prevent Emacs from creating these links because they cause the directory timestamp to be modified, which causes our build system to rebuild an entire module instead of compiling and linking for one changed file :/
Thanks for any input!
Update: In order to prevent Emacs from creating interlocking files permanently, you can change src/filelock.c and build a custom binary:
void
lock_file (fn)
Lisp_Object fn;
{
return;
// Unused code below...
}
Update 2: Arne's answer is correct. It's now possible to disable lock files in the latest Emacs (24.3.1), by adding this to your .emacs file:
(setq create-lockfiles nil)
Update: Emacs 24.3 has been released with full support for this new setting!
In the current trunk of emacs, you can simply customize the variable create-lockfiles:
C-h v create-lockfiles
Documentation:
Non-nil means use lockfiles to avoid editing collisions.
In your init file, you can set
(setq create-lockfiles nil)
Get it via
bzr branch bzr://bzr.savannah.gnu.org/emacs/trunk emacs-trunk
make
src/emacs
(I found out about this, because I decided to get active and just add an option like that myself… :) )
The symbolic link is emacs' file interlocking system: the symbolic link indicates that an instance of emacs is editing this file. If another instance tries to edit the same file, emacs will issue a warning. See http://www.gnu.org/software/emacs/manual/html_node/emacs/Interlocking.html
This has nothing to do with auto-save.
I cannot find how to modify or disable file locking from within emacs.

Bookmark+ using a temporary file, despite having asked for a specific file

After typing C-x r l I get a buffer called *Bookmark List*
In this buffer I see:
Bookmark file:
/tmp/bmkp-temp/19236bkt
If I open help (i.e. press h), I see:
Bookmark file: /tmp/bmkp-temp-19236bkt
Sorted:
Filtering: none
Marked: 0
Omitted: 0
Autosave bookmarks: no
Autosave list display: yes
This is even though I have the following in my .emacs file:
(setq bookmark-file "~/.emacs.d/bookmarks")
(setq bookmark-default-file "~/.emacs.d/bookmarks")
(setq bmkp-default-bookmark-file "~/.emacs.d/bookmarks")
(setq bmkp-last-as-first-bookmark-file nil)
Why is it using a different bookmark file from the one I specified?
I also noticed that when I load Emacs the following happens:
Emptying bookmark file `/tmp/bmkp-temp-23808OMn'...
Saving file /tmp/bmkp-temp-23808OMn...
Wrote /tmp/bmkp-temp-23808OMn
Emptying bookmark file `/tmp/bmkp-temp-23808OMn'...done
...
Helm completion enabled
Emptying bookmark file `/tmp/bmkp-temp-23808bWt'...
Saving file /tmp/bmkp-temp-23808bWt...
Wrote /tmp/bmkp-temp-23808bWt
Emptying bookmark file `/tmp/bmkp-temp-23808bWt'...done
...
Emacs goes on a spree deleting temporary bookmark files. ?
Perhaps you were trying to use "bookmark-file bookmarks"? Or anyways, accidently hit C-x p x?
These are claimed to correspond, at EmacsWiki: Bookmark Plus / Bookmark-File Bookmarks, where they say, "bmkp-set-bookmark-file-bookmark, bound to C-x p x". For my Emacs, this is not true.
By typing C-x p C-h, I can check key-bindings that start with C-x p. I find
C-x p x is bound to bmkp-toggle-autotemp-on-set, and
C-x p y is bound to bmkp-set-bookmark-file-bookmark.
Then, the link should say C-x p y instead.
It looks like something, somewhere (e.g. check your .emacs file) has turned on bmkp-temporary-bookmarking-mode. When that mode is on, any bookmarks you create are for the current session only -- they are not saved to your bookmark file.
And that means that your bookmark-file location settings are ignored. (Note, BTW, that bmkp-default-bookmark-file is a function, not a variable -- it is not something that you set. And you don't need all of those bookmark-file settings; some are redundant: old names from old versions of Emacs bookmarking.)
I don't know why you are getting multiple temporary bookmark-file creations and saves. You didn't provide a complete recipe. You should get only one such. This is all I see in *Messages* in this regard, for instance:
Emptying bookmark file `c:/DOCUME~1/me/LOCALS~1/Temp/bmkp-temp-5348su1'...
Saving file c:/Documents and Settings/me/Local Settings/Temp/bmkp-temp-5348su1...
Wrote c:/Documents and Settings/me/Local Settings/Temp/bmkp-temp-5348su1
Emptying bookmark file `c:/DOCUME~1/me/LOCALS~1/Temp/bmkp-temp-5348su1'...done
It also appears that you have a lot of stuff going on (Helm etc.). When trying to understand or debug a problem, it helps to narrow things down as much as possible. Who can tell what other interactions might be involved here?
All of that said, my advice would be to not start out using the temporary bookmarking mode. I would not suggest you use that until you are quite familiar with Bookmark+. You can use temporary bookmarks without using this mode.
Here is the doc about using temporary bookmarks:
http://www.emacswiki.org/cgi-bin/wiki/BookmarkPlus#toc55
Finally, as Stefan suggested, please follow up by email. It's a lot easier for debugging/discussing things in detail.
Thx -- Drew
Update 2019-04-21:
I think what might have happened is that you quit Emacs with bmkp-temporary-bookmarking-mode enabled. Although Bookmark+ (correctly) does not save the file of temporary bookmarks it was not preventing the recording of bmkp-last-as-first-bookmark-file from being updated to point to the temporary file. In your next Emacs session that temporary file (if it still existed) was loaded because of bmkp-last-as-first-bookmark-file.
That should be OK now. Enabling bmkp-temporary-bookmarking-mode now resets bmkp-last-as-first-bookmark-file to nil, so if you quit with the temp mode still enabled, then when you load your bookmark file in a new session the file that is read is the value of bookmark-default-file. (The value of bookmark-default-file is never changed, except by your
customizations.)
It's quite an old question, but since I had just the same problem and the other answers didn't help me I'll post my solution:
I'm using desktop files from desktop.el and the temporary mode was set there in the desktop file! Removing that setting from all my desktop files fixed the problem.
This might be handy:
find ~ -name .emacs.desktop -print0 | xargs -0 grep -l bmkp-temporary-bookmarking-mode