What is the correct way to show menu / help screens in Emacs? - emacs

When using tools like Org-mode and Magit the mode will sometimes show help menus. For instance, org-mode export will show a nice menu that accept single keys and then executes some command. In Magit, when looking at the status view it will accept tabs to expand the staged and commit areas.
These areas, for both Git and Org, are nicely placed to take up some portion of the emacs frame that is mostly convenient. How does emacs do choose this?
Additionally, these views are read-only, up until the user presses tab in the case of Magit and the status view. Is there a best practice when creating these views which control editing, but allows the mode to edit the file and present alternative text?
Perhaps the answer is take a look at these function A, B, and C. Which is fine, I'm just learning and experimenting on my own.

Magit in particular is not the simplest introduction to popup buffers in Emacs, but it certainly is sophisticated and a good read. Find magit-popup.el on your machine, for example M-x find-function RET magit-popup-mode-setup. To me, that function looks like a good candidate to start reading that file. You can see the macro magit-define-popup in use for example in magit-push-popup in the file magit-remote.el
In the end, it boils down to opening a new buffer in a new window and give it a dedicated major mode which has all the key-bindings.
Another good candidate is the family of temp-buffer-* functions.
Hope, that gives some pointers to start reading.

An easy way to show menus/help screens à la Magit and org-mode is with Hydras:
http://wikemacs.org/wiki/Discoverability#Hydra
https://github.com/abo-abo/hydra/
https://github.com/abo-abo/hydra/wiki
It's a short elisp method to write and it will give you a menu like org-mode. For example:
(defhydra hydra-zoom (global-map "<f2>")
"zoom"
("g" text-scale-increase "in")
("l" text-scale-decrease "out"))
ps: it's not what org-mode and magit use. Magit's system wasn't re-usable until recently and I don't know how it compares with Hydra. A nice feature of Hydras is that you can tell it to not disappear after a keypress, so than you can press many keys in a row.

Related

TODO Tool window in Emacs?

I'm looking for a functionality like:
the TODO tool window of IntelliJ IDEA (see https://www.jetbrains.com/help/idea/todo-example.html) or
the Tasks list of Eclipse (see https://dzone.com/articles/to-do-lists-with-eclipse-tasks-view).
And I'd like that window to be opened automatically (if not empty) when opening any file or, at least, to have a message in the echo area stating that there are some TODO/FIXME items in the file I'm currently opening.
So far, I did not find any matching package, only things (like fic-ext-mode) that would highlight TODO and FIXME in comments for common programming languages, but no more.
Is there something else, closer to what I'm looking for? I'm certainly not the first one looking for such a feature in our favorite editor ;-)
hl-todo has hl-todo-occur, which opens an occur buffer of all the keywords it's configured to highlight in the current buffer. You should be able to add it to a major mode hook like so:
(add-hook 'prog-mode-hook #'hl-todo-occur)
But this doesn't work. I think it's because hl-todo-mode is activated in prog-mode-hook, and it isn't ready yet. I don't have time to track this down right now.
If you use magit, I just saw a new package magit-todos. I haven't tried it, but it looks pretty nice.
Not aware of an existing module. It would be nice to have one. If you can write, use elisp and M-x Highlight-regexp and M-x occur and then write a hook to open occur window when you open a file. May be a macro will do for this too. You can do more with elisp, such as make occur window renamed as TODO-window and parse the entries to convert into org-mode table to sort entries while preserving the clicking etc.

Emacs: Automatically show files in directory with find-file

When navigating through a deep directory tree with find-file (C-x C-f), I often find myself 1) tapping the Tab key to autocomplete a directory name, and 2) immediately tapping the Tab key again to see the contents of that directory. I do this so routinely that I'd love it if I didn't have to hit Tab a second time to see those contents.
Is there a way to automatically display the contents of a directory after autocompleting its name?
Also, I've played around with ido-mode and helm, but I wasn't a huge fan of either, so I ended up switching back to the default find-file.
I hesitate to say this, as I doubt you will find it satisfactory wrt what you are looking for, but in case it helps:
You can configure Icicles so that it immediately shows all candidates and updates the matches as you type. See Icicles Incremental Completion.
The relevant options are icicle-show-Completions-initially-flag and icicle-incremental-completion (and maybe icicle-find-file-expand-directory-flag).
(There are also options icicle-incremental-completion-delay and icicle-incremental-completion-threshold.)
If you don't like ido-mode or helm, you might find icomplete-mode more to your liking: it doesn't overwrite as many keybindings as ido does.

How to achieve this in Emacs?

I saw the feature shown and described below in Sublime Text and was curious to know how does one achieve it in Emacs?
A brief description of the feature:
Have a condensed view of the entire code/text file currently opened and highlight the region, in the very same condensed view, which is currently being viewed. Clicking on any part of the condensed view would bring that part in focus.
Although I know, almost certainly, that I would rarely use this feature since it would be, in my view, a estate hog, considering the fact that I have even had my scroll-mode disabled, but still I am curious to know how it can be done in Emacs.
And yeah I went through(skimmed) Sublime's feature list to find the name of the feature, so that I could then try to find it for Emacs, but couldn't. Therefore, another question: What's this feature called?
Original source of the image above.
There is MiniMap package. From EmacsWiki:
Put minimap.el in your load path.
(require 'minimap)
Use M-x minimap-create in a buffer you’re currently editing.
Use M-x minimap-kill to kill the minimap.
Use M-x customize-groupRETminimap RET to adapt minimap to your needs.

Do you use Emacs tabbar?

The emacs tabbar.el package adds (buffer)tabs to each window and comes standard with aquamacs and can be added to emacs23 with the emacs-goodies-el package.
Are any of you hardcore emacs users actually using tabbar? I'm sort of used to having tabs, but I would like to know if working without them could be more productive, and if there are other ways besides checking your bufferlist (C-x C-b) to get an overview of your current project files.
As a side note, I really like textmate's project drawer (and tabs), but anything similar in emacs looks just plain hideous.
I've tried using it, but I felt it constraint my workflow rather than improve it. There are a lot of excellent Emacs modes to help with the organization of many buffers and I simply don't feel mapping buffers to tabs is one of those ways.
Just think about the most basic scenario - a lot of tabs. How different programs deal with it - limit the maximum tabs(IntelliJ IDEA); enable tabs bar scrolling(Firefox); infinitely reducing the tabs size(Google Chrome); creating rows of tabs(IntelliJ IDEA)... None of this solutions is that great and by not having tabs in Emacs we have one less problem to worry about. At least this is my subjective opinion - others will most certainly disagree... I personally need nothing more than ido and and iswitchb.
A video of ido in action: http://www.youtube.com/watch?v=lsgPNVIMkIE
Ya, I use tabbar, along with sr-speedbar.
I customize tabbar to show files in specific groups, and mod some keybindings to make navigating the files easier.
FWIW, here's the relevant section from my ~/.emacs:
(require 'tabbar)
; turn on the tabbar
(tabbar-mode t)
; define all tabs to be one of 3 possible groups: “Emacs Buffer”, “Dired”,
;“User Buffer”.
(defun tabbar-buffer-groups ()
"Return the list of group names the current buffer belongs to.
This function is a custom function for tabbar-mode's tabbar-buffer-groups.
This function group all buffers into 3 groups:
Those Dired, those user buffer, and those emacs buffer.
Emacs buffer are those starting with “*”."
(list
(cond
((string-equal "*" (substring (buffer-name) 0 1))
"Emacs Buffer"
)
((eq major-mode 'dired-mode)
"Dired"
)
(t
"User Buffer"
)
)))
(setq tabbar-buffer-groups-function 'tabbar-buffer-groups)
(global-set-key [M-s-left] 'tabbar-backward)
(global-set-key [M-s-right] 'tabbar-forward)
There's lot's of other tips on emacswiki:
http://www.emacswiki.org/emacs/TabBarMode
no.
I use iswitch-b
C-x b "first few letters of buffer", then C-s to rotate to the specific file I want takes me under 2 seconds without me having to move hand to mouse.
No. I could possibly be convinced to try it again with the right customisation, but by default it's pretty useless for me, as I habitually have in excess of 100 buffers open. ibuffer with its filtering and grouping is the best way for managing large numbers of buffers that I've tried.
I like to use speedbar for quick buffer navigation. I have in my .emacs
(speedbar-change-initial-expansion-list "buffers")
(global-set-key [f8] 'speedbar-get-focus)
so when I hit F8, a new frame pops up with a list of open buffers, there you can move point over the buffer you want to select and to activate it. One more F8 goes back to the main frame.
tabs are not reserved for mouse users. look at vim possible workflow: gt to go next tab, or gT to go previous. Say you've one dedicated window for vim: you might easily switch from one buffer to another. Yes, tabs are probably for users with few buffers. if you have hundreds, this won't work.
Quite frankly, you'll find better editors than emacs when speaking of tabs, menus and toolbar. Emacs clearly encourages you to use your keyboard and leave your mouse asleep.
Tabbar or any other tab management tool will have difficulties when you'll have lots of buffers opened. You also don't want to show all your buffers in tabs. Having to remove your hand from the keyboard to grasp the mouse and click on a tab and then remove your hand from the mouse and put it onto the keyboard is clearly a waste of time when a simple keystroke could be used instead.
The best thing you could do to your emacs and to you is to have the following configuration in your .emacs :
(menu-bar-mode -1) ;hide menu-bar
(scroll-bar-mode -1) ;hide scroll-bar
(tool-bar-mode -1) ;hide tool-bar
That will force you to forget the old way of doing things using a mouse (like using tabbar, or menus...), and to use your fingers instead.
Up until now, I haven't tried it, but before I switched back to GNU Emacs from XEmacs, I used the XEmacs tabs very heavily. I found that when I had many source files open, it was one of the fastest ways to jump to the correct file.
Now that I know about tabbar, I am trying it; and so far, I like it.
John
Tabs are really only useful if you use the mouse, and one of the main benefits (to me) of Emacs is that I can avoid the mouse.
So, no, tabbar isn't useful in general.
I did find the tabs useful when I was browsing web pages (using w3m), but I was using the mouse in that case...
Tabbar looks like it is godforsaken
So what about elscreen?
Can be found via http://melpa.milkbox.net/#/elscreen - or installed emacs-elpa (or melpa).
Elscreen is very useful for me.
C-x b<RET> always gives you the last edited buffer. And what do you do with tabs ? Mostly switch back & forth between two files. There you go.

Better control over Emacs windows

I spend a lot of my time in emacs, and for the most part it's wonderful. But one thing really drives me nuts when I'm deep in it, and that's control over which window various new buffers are opened in. When I do find-file, it always opens in the current window, and this is what I like. But tons of other modes like to split my windows for me, change the layout, and do various other things that annoy me. For example running M-x manual-entry seems to have no rhyme or reason about where it opens the manpage, and various org-mode commands do the same thing, closing windows I want to keep open, etc. I don't like having to redo my layout everytime I want to look at my org agenda or open a manpage.
In short, is there anyway to globally control which windows are used for modes that want to open in a window other than the current one? Can I direct them more easily? Or will I have to hack each mode to act the way I want it to?
Try Winner mode:
http://www.emacswiki.org/emacs/WinnerMode
It provides an undo/redo for changes to the window configuration.
This question has always bugged me too. I found this:
http://www.gnu.org/software/emacs/elisp/html_node/Choosing-Window.html
It looks like you can use (setf pop-up-frames t) to make stuff show up in a new frame.
Also, it looks like you can use display-buffer-function to override the display function (how buffers are chosen.) Of course, you'd have to be good at elisp.