ido-switch-buffer and bury-buffer - emacs

I've recently started using ido-mode, which, overall, is pretty nice. But one thing seems especially broken, and I'm wondering if there's a setting (ha) buried in there to fix it.
ido-switch-buffer doesn't seem to care about buried buffers. That is, if I use bury-buffer, and then ido-switch-buffer, the first choice is often the one I just buried.
Is there an easy way around this? The whole point of burying a buffer is that I don't want to see it again any time soon.

Acording to the documentation (C-h f bury-buffer)
Put BUFFER-OR-NAME at the end of the list of all buffers.
There it is the least likely candidate for 'other-buffer' to return;
thus, the least likely buffer for C-x b to select by
default.
So, if you use bury-buffer the buffer will be still available (at the end of the list), so it's normal that ido-switch-buffer find it.
If you don't want to see that buffer ever, you should think of closing it.

I can't reproduce this. On Emacs 23, as far as I can tell, ido-switch-buffer lists the buffers in the correct order.
In any case, you might try out iswitchb instead. It's kind of like ido, only older and more specific to buffer switching. If you like it, you can use iswitchb for buffer switching and ido for everything else.

can't reproduce this either: when i bury a buffer and call ido-switch-buffer afterwards, the buried buffer is NOT at the front of the switch list.
i have done quite a bit of ido customization (to get it working well with dired, etc), but my main ido settings are:
(setq ido-show-dot-for-dired t)
(setq ido-default-file-method 'samewindow)
(setq ido-default-buffer-method 'samewindow)
(setq ido-confirm-unique-completion t)
(setq ido-max-dir-file-cache 20)
my ido.el version is "1.57 released on gnu.emacs.sources adapted for emacs 22.1".
hth.

Use next-buffer or previous-buffer

FWIW, the default completion behavior of switch-to-buffer (C-x b) in Emacs-24 has been changed to use substring-match completion, so its behavior is similar to IDO while obeying the principle that "the default buffer shouldn't be the one I just buried". You can make it even more similar by turning on icomplete-mode (which does not change the completion behavior itself, but displays the completion candidates at the end of the minibuffer).

Related

How do I revert a sparse-tree view in org mode?

I am learning org mode, and just found out about sparse trees (C-c / t and its kin). How can I go back to the original, unsparse, view of my org document?
I found out by trial and error that TAB-cycling the top node works, is there a better way?
C-c C-c should clear out the sparse-tree hiding and highlighting, but as far as I know, you can't just go back to the "last view" you had of it. If you want to go back to the full-view, use Shift-Tab to cycle all entries.
So, it's now 2018 and (AFAIK) this feature still doesn't exist.
The best workaround I've found so far, is to create an indirect buffer (C-x 4 c) and then run org-sparse-tree in there. The original window remains unaffected, so you keep your view, and changes to the indirect buffer will update the original buffer (and vice-versa). When you're done, you just close the indirect buffer.
I usually just run the org-mode command which seems to get me back to square one.
Ben K. was on the right track. Indirect buffers are one of emacs' most powerful features.
This function does what I would have expected org-show-todo-tree to do: create a new buffer showing undone TODO items, don't screw up my org file's tree state, and clear the unnecessary occur highlighting.
(defun org-todo-buffer ()
"Create new indirect buffer with sparse tree of undone TODO items"
(interactive)
(clone-indirect-buffer "*org TODO undone*" t)
(org-show-todo-tree nil) ; mimics interactive usage
(org-remove-occur-highlights)
)
In this new buffer you can change TODO item states which are reflected in your org file, and you can simply kill the indirect buffer when you are done with it.
Coming to this very late, I noticed that selecting all tags then un-highlighting/un-narrowing seems to do the right thing.
C-c \ *
C-c C-c
TAB-cycling anywhere only hides the entries highlighted by org-sparse-tree.
To remove the overlays, you need to actually edit the buffer.
As you said, you can there by visibility cycling with S-TAB, but I personally don't like visibility cycling because I'm never sure where I am in the cycle.
So I just created this simple org-agenda-custom-command that shows everything without highlighting. Just add it to your .emacs file.
(setq org-agenda-custom-commands
; ... other commands
`(("z" "All" occur-tree "."
((org-show-entry-below t)
(org-highlight-sparse-tree-matches nil)))))
There probably is a better way to do this, and the beauty of SO is someone will tell us :).
What I usually do to work around this is to use C-x C-v RET (find-alternate-file) or M-x revert-buffer. This works only if you don't have unsaved edits.
I found that the (setq org-agenda-custom-commands.. answer works the best for me.
Use with (sorry, it wasn't obvious to me):
C-c a z

How can I more easily switch between buffers in Emacs?

I've recently started using emacs and I'm enjoying using it for the most part. The only thing I'm not enjoying, is switching between buffers. I often have a few buffers open and I've grown tired of using C-x b and C-x C-b, are there any packages that make switching between buffers easier? I've looked into emacs wiki on switching buffers and I'd appreciate insight/feedback on what are are using/enjoying. Thanks.
UPDATE: iswitchb-mode is obsolete in Emacs >= 24.4, replaced by ido.
All of the features of iswitchdb are now provided by ido. Ross provided a link to the documentation in his answer. You can activate with the following in your .emacs (or use the customization interface as Ross suggests):
(require 'ido)
(ido-mode 'buffers) ;; only use this line to turn off ido for file names!
(setq ido-ignore-buffers '("^ " "*Completions*" "*Shell Command Output*"
"*Messages*" "Async Shell Command"))
By default, ido provides completions for buffer names and file names. If you only want to replace the features of iswitchb, the second line turns off this feature for file names. ido will ignore any buffers that match the regexps listed in ido-ignore-buffers.
The behaviour described below for iswitchb-mode applies equally to ido for switching buffers.
iswitchb-mode (Emacs < 24.4)
iswitchb-mode replaces the default C-x b behaviour with a very intuitive buffer-switching-with-completion system. There are more sophisticated options, but I've never needed more than this.
After you hit C-x b, you are presented with a list of all buffers. Start typing the name of the buffer you want (or part of its name), and the list is narrowed until only one buffer matches. You don't need to complete the name, though, as soon as the buffer you want is highlighted hitting enter will move you to it. You can also use C-s and C-r to move through the list in order.
You can turn it on by default with this in your .emacs:
(iswitchb-mode 1)
You can also tell it to ignore certain buffers that you never (or very rarely) need to switch to:
(setq iswitchb-buffer-ignore '("^ " "*Completions*" "*Shell Command Output*"
"*Messages*" "Async Shell Command"))
You can use C-x <right> (next-buffer) and C-x <left> (previous-buffer) to cycle around in the buffer ring. You could bind S-<right> and S-<left> to these functions. (S is the "super-key" or windows-key). This way you can save some keystrokes.
Moreover, note that C-x b has a default entry, i.e. it displays a standard value (most of the time this is the previously viewed buffer), so that you don't always need to enter the buffer name explicitly.
Another nice trick is to open separate windows using C-x 2 and C-x 3. This displays several buffers simultaneously. Then you can bind C-<tab> to other-window and get something similar to tabbed browsing.
M-x customize-group ido then set Ido Mode to Turn on both buffer and file and set Ido Everywhere to on. Then click the Save for future sessions button at the top and enjoy ido magic for both files and buffers. Read the docs to get a sense of how to use ido.
Also, take a look at smex.
ido-mode provides an efficient way to switch buffers.
ibuffer is best for managing all opened buffers.
anything is good for selecting an interested thing from different
sources. (for eg: a single key can be used to switch to another
buffer or to open recently closed file or to open a file residing
in the same directory or ... anything you want ... )
If you've looked at the Emacs Wiki, you probably have all this information already, but here are a few other relevant Q&As:
Emacs: help me understand file/buffer management
Buffer switching in Emacs
How to invoke the buffer list in Emacs
My toolkit consists of ibuffer, windmove+framemove, winner-mode, and a custom binding to make C-xleft/right and C-cleft/right less of a hassle to use.
I have mapped the "ยง"-key to 'buffer-list and I find it to be very efficient.
I've started using anything for a couple of days and I'm really liking it: http://www.emacswiki.org/emacs/Anything .
Emacs-fu has an good intro to anything: http://emacs-fu.blogspot.com/2011/09/finding-just-about-anything.html
My favourite function for this is helm-mini which is part of helm.
As other helm functions, it allows incremental narrowing of the selection. It also searches your recently visited buffers, which is a really nice way to re-open a buffer. Helm can be a little surprising at first and as a new Emacs user, I found it visually overwhelming and I preferred ido or ibuffer which have been suggested in other replies. But now I absolutely love it and use it all the time for countless things.
Something that I realized by accident and that can be useful:
mouse-buffer-menu is by default bound to <C-mouse-1> (Control key + mouse left click) and opens a popup with a list of the current buffers.

why does set-default-font affect find-file-other-window?

I recently added the line
(set-default-font "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1")
to my .emacs file. After that find-file-other-window always opens a new window instead of utilizing existing windows. Why would that happen!? How can I fix it?
I don't understand how all this font-config magic works, so if it's actually obvious I'm sorry.
Edit: I have a pretty large resolution, and my font size has decreased pretty significantly. Does find-file-other-window take into account available character space? Perhaps it's deciding there's sooo much room it can afford to just open windows willy nilly.
find-file-other-window ultimately calls display-buffer, which runs a complex algorithm to decide whether to reuse an existing window or make one and how. In particular, if display-buffer decides it needs to create or recycle a window, it tries calling split-window-preferred-function to split the biggest window. By default, split-window-preferred-function is split-window-sensibly, which is willing to split windows vertically if they are more than split-height-threshold lines high, or failing that horizontally if they are more than split-width-threshold columns wide.
It looks like you want
(setq split-width-threshold nil)
(setq split-height-threshold nil)
N.B. This answer applies to GNU Emacs 23. Earlier versions didn't have horizontal splitting. Later versions may do things differently.
A few ways to find this out (none straightforward):
If you guess that what's going on is called splitting a window: M-x apropos RET split RET shows a number of variables and functions, and you might figure out which ones are relevant. Or if you guess that there's an option (there often is), C-h v split- TAB shows promising leads.
The documentation for find-file-other-window references Displaying Buffers. (You have to go to the Elisp manual for this level of detail; within Emacs, C-h i m elisp RET brings up the Elisp manual, and i find-file-other-window RET leads you to the documentation for this function.) It's less clear that pop-to-buffer is the passage to read there; it references Choosing Window which contains the sought after information.
C-h f find-file-other-window RET shows the built-in documentation for the function. It links to display-buffer. The description of display-buffer doesn't describe its operation in detail, so from there you need to either consult the Elisp manual as above or explore the source of display-buffer by clicking on window.el.

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:

Updating font-lock keywords in emacs without major mode reload

I am doing small modification to SLIME, so that I can get all currently loaded symbols from Lisp, analyze them and make font-lock fontify them.
I managed to do all these steps, but I have a small problem - when keyword list changes in font-lock the buffer is not updated unless you restart the major lisp-mode. I don't want to restart lisp-mode every time I update keywords, because I have several hooks on lisp-mode that I want to run only when I load the file for the first time.
Is there an other way to update font-lock so it reads all then new keywords and fontifies the buffer accordingly? Switching off font-lock and using font-lock-fontify-buffer does not do the trick.
UPD: Added bounty - the question is still up. I need a way to reload font-lock keyword without reloading major mode.
Ok, how about this instead:
(defun my-font-lock-restart ()
(interactive)
(setq font-lock-mode-major-mode nil)
(font-lock-fontify-buffer))
You could temporarily clear the mode hook variable and restart it:
(defun my-restart-lisp-mode ()
(interactive)
(let ((lisp-mode-hook nil))
(normal-mode)))
Triggering the major-mode is not what makes font-lock do its thing. I am not intimately familiar with the internals of SLIME or lisp-mode, but just setting the variable should make it work. Toggling font-lock-mode will make font-lock start refontifying with the new keywords in mind, as should font-lock-fontify-buffer.
I hack on cperl-mode, mostly, and it is a simple matter of cperl-init-faces (which sets the internal font-lock variables) and a restart of font-lock. lisp-mode should not be much different, except for not needing a call to cperl-init-faces ;)
Edit: some experimentation with lisp-interaction-mode reveals that even restarting font-lock-mode is not strictly necessary. Just changing font-lock-keywords is enough, as long as you re-trigger fontification somehow. (Editing text, font-lock-fontify-buffer, etc.)