I am using emacs and the auto-newline feature is not working as expected. I have a pretty large number of customizations done to my emacs. So it would be no wonder if one of the other customizations is not what auto-line is expecting. I would like to know if there is a way to know the list of commands (list of emacs commands) executed by emacs at a particular point, for e.g. when ctrl-s ctrl-c or in my case when auto-line feature is called.
edit : I think you have misunderstood the question. I would like to know what command emacs calls 'internally'.
I believe view-lossage is what you're looking for -- M-x view-lossage, or C-h l.
If you want to know what a keystroke is bound to, consider using describe-key, which is usually bound to C-h k.
Basically at this point, you need to bite the bullet and learn some Emacs-lisp. The debugger is what you are looking for to dig further into your problem (I use edebug). It's not just about seeing what functions get called, you also need to see the values of the relevant variables when those functions are called.
If you feel you're not up to it, then you can bi-sect your init file until you find the culprit, but at that point you still need some Emacs-lisp to investigate further.
To add to what #event_jr said --
What you seem to be asking is the history of the functions called by the command you last invoked. (You speak of Emacs "internal commands", but it seems you just mean functions.)
To get that history for any given command you invoke (e.g., by a key), use M-x debug-on-entry and then enter the command name. The next time you use that command, you can walk through its execution in the Emacs debugger (hit d to step, c to continue past a step).
Related
I know how to enter recursive edit mode when query-replace (M-%), but sometimes I really don't want to modify the code instead I'm just in searching. Such as when I was reading code, and from one point I saw a function call, then I want to jump to the declaration of the fucntion (C-r Enter PageList::Init), when I have read the declaration I want to jump back to the calling of the function.
How to enter recursive edit mode when searching (not only when query-replace)?
You can open a recursive edit while you are searching, if you use Isearch+. Then, C-x o is bound during Isearch to command isearchp-open-recursive-edit:
Invoke the editor command loop recursively, during Isearch.
Use C-M-c to end the recursive edit and resume searching from there.
Or use abort-recursive-edit to exit the recursive edit and cancel the previous search.
If you do not want to use Isearch+ then this is all you need:
(defun isearchp-open-recursive-edit ()
"Invoke the editor command loop recursively, during Isearch.
Use `\\[exit-recursive-edit]' to end the recursive edit and resume searching from there.
Or use `abort-recursive-edit' to exit the recursive edit and cancel the previous search."
(interactive)
(with-isearch-suspended (recursive-edit))))
(define-key isearch-mode-map "\C-xo" 'isearchp-open-recursive-edit)
If you are asking about recursive editing generally, and not just during search, then the answer is command recursive-edit. Just use M-x recursive-edit to open a recursive edit. You can also bind this command to a key, of course.
(If the minibuffer is active, then you normally cannot use M-x recursive-edit. In that case, bind a key in the minibuffer keymaps to recursive-edit. Or you can set option enable-recursive-minibuffers to non-nil, to be able to invoke M-x recursive-edit from a minibuffer.)
You enter a recursive edit by calling recursive-edit, but there is no default binding which invokes this anywhere (and doing so arbitrarily might be hazardous).
In the case of query-replace there is some special-case handling which goes on when you type C-r which saves the current match data/point/mark/buffer/window configuration before entering the recursive edit, to ensure that it can restore things when you exit from it.
This need to wrap some situation-specific custom handling around calls to recursive-edit is very common to the existing use-cases, so there might not be a safe way to invoke it generally.
My guess is that custom handling would certainly also be needed to support it during an isearch, and I see no such facility.
Do note that Emacs pushes point to the mark ring when you begin an isearch; so for your specific use-case you would simply jump to & pop the mark with C-uC-SPC
From your workflow description, I'm not sure you really need recursive edit mode.
When you do a search in emacs, the current point is saved. On my system C-r is reverse isearch. When I hit it, I'm prompted for the search string and hit enter. This takes me to the first 'hit'. Hitting C-r againi takes me the next hit etc. Once you find the text you want, provided you don't hit enter, you can read the code and then hit C-g to cancel the search. This will jump your cursor back to the point where you started the search. This is fine provided you can see all the code you want to read on screen.
When you can't read all the code on screen and you need to move around in the buffer, you have to hit enter. Once you do this, you have lost the saved point and I suspect this is where you thought of using a recursive edit mode so that you can jump back once you finish. However, this won't work quite as you want because as soon as you hit enter to select the searched for string, you will come out of recursive mode and lose the saved point.
There are a couple of ways to fix this workflow to achieve what you want. In fact, your workflow is quite a common requirement. Because of this, many programming modes already have this functionality built in. Therefore, the first thing to do would be to ensure your mode doesn't already have this - it is probably called something like jump to definition or similar.
If your mode doesn't have this support, then you can get what you want by saving the point and then jumping back to it later. This is a really handy technique. All you need to do is C-SPACE twice. Then later, after moving the point to a new locaiton, you can just do a C-u C-SPACE to jump back to that point. From the emacs manual
Instead of setting the mark in order to operate on a region, you
can also use it to “remember” a position in the buffer (by typing
‘C-SPC C-SPC’), and later jump back there (by typing ‘C-u
C-SPC’). *Note Mark Ring::, for details.
Suppose I want to install a new package. To do this I need to remember that M-x package-install RET package-name is the sequence of keystrokes to type into emacs to do this.
If I forget this keystroke, my go to solution is to google the action I want to complete and browse through the results until I find the right command.
I suspect there is a better way to look up emacs commands and what they do though. If so, can anybody point me to it?
Thanks!
The number one goto command for this would be the apropos-command, which is invoked by using C-h a (or M-x apropos-command), and then typing a search query for the command.
If you know the name of a function, you can use C-h f which runs the describe-function command to get more details about the command.
Lastly, if you know the key sequence, and want more details regarding the command you run, you can use C-h k - describe-key to have emacs tell you what command and the documentation for that command when typing a sequence of keys.
You can get a more complete list of help commands by typing C-h ?.
The built-in manuals are the other obvious places to look, and you can search each one using its index, or isearch through the full-text of the manual.
https://stackoverflow.com/a/22380057/324105
If you use Icicles then the equivalent of apropos-command is built into every command that reads a command name, and you can change the pattern on the fly to tweak the set of matches. See apropos completion.
Whereas with apropos-command you need to provide at the outset the regexp or the complete list of keywords to match (and you need to get them right), with Icicles you can modify/correct them incrementally, and you can add more patterns progressively (progressive completion).
And when you have a set of matches for your pattern(s), you can see the complete doc for each on demand, as opposed to searching the output from apropos-command (which only shows partial doc anyway).
In addition, Icicles extends the standard apropos commands in various ways.
I would like to, after switching to the buffer where I usually run commands, navigate the history by searching it, rather than navigate one-command-at-a-time at the end of the buffer (e.g. C-p).
Basically I would like to "Reverse I-search" the command history at the end of the buffer, rather than search the buffer.
Did anyone code a working solution? Note that I noticed there is a Command History buffer available, but here it is just a bunch of text and it is not grouped well enough I think to use.
As in a terminal, you can use M-r to search backward. It works in comint-mode, but it also work elsewhere, like in M-x (M-xM-rpatternRET).
Yes, with Icicles.
In Icicle mode, command icicle-comint-search is bound to C-c ` in shell buffers. It gives you the behavior you are looking for. It is described here.
It uses only stuff that is in the currently visible history as candidates, however. If you want to access stuff from your history from previous sessions then use command comint-input-ring, bound to C-c TAB, instead. (This is explained in the same doc.)
I would find a way to execute the commands in the file emacs. Emacs and therefore automatically.
For example I often use: highlight-80
So I'm forced to type every time: Meta key + highlight-80 +-fashion
it's the same with linum-mode and plenty of other.
I have been trying to put in the file emacs.:
(highlight-80 +-mode)
But the option is not enabled.
Thank you in advance for your help. I am looking desperately for a moment, emacs is my working tool quotidient.
Regards
Use C-h f or C-h v, and read the Emacs manual about such choices.
Some of them are user options (variables), whose values you can customize, using M-x customize-option, so the default setting becomes what you want.
Others are modes, which you can call/set in your init file (~/.emacs) --- see the Emacs manual for how to do that. Typically, you use a positive number to turn a mode on and a negative number to turn it off. E.g.: (menu-bar-mode -1) in your init file turns off the use of a menu bar.
In sum, the Emacs manual (C-x r) is your friend. Sit down and have a first chat with it.
You seem generally a bit unsure about how customising Emacs works, so reading the manual on this topic should probably be your next step:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Customization.html
If you are not using the current stable release (Emacs 24.3 at the moment), there's a chance that some of that information will not apply. The in-built manual is, of course, always correct for the version you are running:
C-hig (emacs) Customization RET
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
If you had a 10 minute hands-on session to teach someone Emacs, what would you show them?
Start emacs: emacs
...
Quit emacs: C-x C-c
What else would you have them do between starting and quitting Emacs, while you stood behind them?
If I had only 10 minutes, I would not teach them any shortcuts at all. All the common shortcuts are available next to the corresponding commands in the menus; those the users can discover for themselves.
The most important things to teach are those that will enable the users to discover/learn by themselves:
That one can quit Emacs with C-x C-c, or File->Quit. When stuck, one should type C-g, and, if that doesn't work, ESC ESC ESC. [This is probably the single most useful advice to prevent total frustration with Emacs, trust me.]
The tutorial: Help->Emacs Tutorial, or C-h t. [This is not a terribly useful shortcut to remember; given how few times one reads the tutorial over the course of one's life...]
The concept that every keystroke in Emacs is bound to a function, and all that Emacs does is execute functions one after another. That there are more functions than can possibly be bound to keys, and functions without a keystroke can be invoked with M-x function-name.
That one can discover what function a particular key invokes with C-h k [keystroke]. Make the user walk through a few of those (including the amusing fact that typing a letter is not special and just invokes self-insert-command, so if one wanted, one could bind the letter 'z' to send email instead :D)
That one can search for possibly useful functions with C-h a (or M-x apropos-command), e.g. C-h a paragraph shows all the commands to do with paragraphs, including what shortcuts will take one to the end/beginning of a paragraph. And that C-h w command-name will tell you if the command is bound to some keystroke or not. [Make them walk through this to discover what the key for undo is -- usually they'll try C-z and it does something annoying :)]
That you can read detailed documentation about what a function does with M-x describe-function (C-h f). That Emacs has great documentation about most things; and M-x apropos-documentation (C-h d) is a great way of discovering stuff.
That one's settings are stored in .emacs, and that one can glean some things by looking at that file even if one don't understand Emacs Lisp.
That one can usually find all keystrokes that "complete" a particular set of keys by typing C-h after it, e.g. 'C-x C-h' will show all the shortcuts starting with C-x; C-h C-h is particularly useful; C-c C-h is useful for mode-specific commands such as when in java-mode or c++-mode or LaTeX-mode, etc. (Hmm, "modes"...)
That when stuck, one can search on http://www.emacswiki.org/. (Or ask a question in the #emacs IRC channel on Freenode, or post to gnu.emacs.help.)
This should fit in 10 minutes, and it's the most important stuff, I think. I wouldn't overload with too many shortcuts to remember; that's pointless anyway -- if the users know how to discover shortcuts, they'll find out shortcuts for whatever they use most frequently. Do have them write down the names of these commands, though, and also about Emacswiki etc.
The important thing is to show them how powerful Emacs is and how universal its model is (all those jokes about it being an operating system are not just jokes). If you just show a bunch of arcane shortcuts to do things they can already do in other editors, Emacs won't seem worth all the trouble. In the same spirit, I also wholly support Anton Nazarov's answer of showing them what Emacs can do (AucTeX if they use LaTeX, etc.) for their specific purposes. Then they can judge for themselves whether Emacs is worth learning, and learn using all the above.
Show them how to start the tutorial: C-h t
C-x M-c M-butterfly
I'd show the most important for that novice user mode.
For example, when I show Emacs to my friends at the faculty of physics, I show them AucTeX with preview-latex and RefTeX. Also iMaxima is great.
If I have to show Emacs to software developers I show them something like JDEE or Python mode with Ropemacs.
Tetris, tramp and w3m can be used to give the idea that Emacs can do everything :)
Then I'd show how to start the tutorial and give link to EmacsWiki.org
i think you show him how
to open and save files
to kill/switch buffers
to switch/kill/split windows
to select a range.
And tell him about M-x . Tell him he write those steps down somewhere. I think basic navigation can be done using arrow keys. Now this is all he needs.
If he knows about M-x , he can easily find search, replace and other stuff.
When giving emacs examples it's never enough to only give the key binding since that can and does vary. C-x M-c is undefined on my system.
When I start XEmacas, until I press a key it alternates between two screens. One of them has the following:
XEmacs 21.4 (patch 21) "Educational Television" (cygwin, Mule) of Tue Dec 4 2007 on vzell-de
`C-' means the control key,`M-' means the meta key
Information, on-line help:
XEmacs comes with plenty of documentation...
M-? F: read the XEmacs FAQ (a capital F!)
M-? t: read the XEmacs tutorial (also available through the Help menu)
f1: get help on using XEmacs (also available through the Help menu)
M-? i: read the on-line documentation
M-x describe-project: read about the GNU project
M-x about-xemacs: see who's developing XEmacs
I would ask that someone to read it out aloud, make sure they understand what it says and then give them, to use in case of emergency, my cell-phone number and a first-aid kit.
I would show the shortcuts for the most common operations such as:
Save: ctrl-x-s
Save as: ctrl-x-w
Open/find file: Ctrl-f
Undo: ctrl-_
Kill buffer: ctrl-x-k
Switch to buffer: ctrl-b
Fill paragraph: M-q
And copy/cut and paste:
Set marker: ctrl-space
Cut: ctrl-w
Copy: M-w
Cut line: ctrl-k
Paste: ctrl-y
Open a file,
Save a file,
Basic navigation,
Set mark, copy, cut and paste,
Show undo and kill ring,
Show C-g,
Show search and replace,
Split window and move to other window,
Switch to other buffers,
Show Tutorial,
Explain Info,
Show dired to:
open some file,
run a command to compress another file,
open, edit and save the compressed file,
open a directory on a remote host,
open & save some file on the remote host,
copy some file from the remote host.
Open a shell and run some long output command and navigate in the buffer.
Learn to use help C-h C-h
Do the tutorial exercice.
Kill something, and another thing, and a third one, then C-y to yank it, and M-y to cycle the kill ring. Big "Woah" factor, quick and cheap. Then tell them it works in their daily shell.
Navigate in the buffer with the mark ring. C-u C-SPC (space) takes you to where you were before and, repeated, cycles though the 16 last positions, regardless of edit state.
You know when you sheepishly undo things just to get "where you were before" ? There you go.
This is a killer emacs ninja trick. Everybody should know it ASAP.
I think the first thing to ask before trying to teach them something is "what do they want to get out of learning Emacs?" AND, are you trying to sell them on the idea of learning Emacs or are they already committed.
If they are a programmer and are looking for a new development environment, show them ECB, how tags work, etc? If they are looking for a general text editor, show them M-x re-builder. If they are looking to write documents quickly and publish them eventually, show them org-mode with HTML and LaTeX exports.
Besides what had been mentioned already I would also show them M-x global-set-key after having showed M-x in general and M-x apropos.
I would tell them that the point of Emacs is that it is infinitely customizable and that one should personalize it to suit one's preferences. I would tell them to try out the standard key bindings first and the advantages of them showing up in Bash, OS X, etc.
C-g
Copy paste
Split Windows
M-x
Apropos
Describe Key
Describe Command
Open files
Switch Buffers
The language-specific development environment, including the debugger and the REPL.