What to teach a beginner in Emacs? [closed] - emacs

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.

Related

Some shortcuts don't work on emacs beginning with C-c

In Haskell-mode, the shortcut C-c C-= is defined to do something.
Trying this shortcut, I realized that emacs do not recognize the shortcut C-c C-=.
Indeed, when I try the shortcut on emacs, the buffer write C-c = is not defined although I pressed C- C-=. I have the same problem with some other symbols like '.' or '§'. But shortcuts like C-c C-l or C-c C-c work.
I try to remove my .emacs but I have the same problem.
a friend have the same problem as me.
Both we are on ArchLinux (64 bits) and we use emacs in console. The keyboard is an azerty.
The problem come from emacs ? Arch Linux ?
Your terminal can't send Emacs C-= so you can't use that key sequence. (Emacs would recognise it if it received it, but that won't happen.)
Your options are:
Run GUI Emacs.
Use M-x name-of-command RET (for whatever command is bound to the key sequence you're not able to use). Use C-hm to see the major mode's bindings, or C-hb to see all current bindings, in order to learn what those command names are.
Create new custom keybindings for the commands in question (i.e. bindings which your terminal can send to Emacs).
Find a different terminal emulator with enhanced key sequence abilities. The vast majority of them will be no better than what you have, because they're all adhering to the limitations of the terminals they're emulating. The most capable one I know of is http://invisible-island.net/xterm/xterm.html but you may need to compile it yourself, and then expect to spend lots of time configuring it. (It's not a trivial solution, though, and xterm requires a GUI environment, so running GUI Emacs is much simpler.)
Use C-x#c<key> instead of C-<key>.
With that last option, you can use a sequence your terminal can send to fake a sequence that it can't send.
C-cC-= would become C-cC-x#c=
If you really wanted to use that last option, you can set a custom binding to simplify the sequence (may be necessary in some instances to avoid conflicting with existing sequences). See the end of https://stackoverflow.com/a/24804434/324105 for more information.
To add to phils' post - another option is an Emacs package (which I wrote), which can teach Emacs and terminals how to properly recognize all PC keyboard keys and modifier key combinations:
https://github.com/CyberShadow/term-keys
The default configuration already includes encoding key combinations like Ctrl=, as well as similar variations.

call emacs commande automatically

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

How can I open a file in subfolder in dired mode fast?

In dired mode, how can i open the file fastly in the subfolder? I found that after loading dired+', the key 'j' isdired-goto-file'. But I cannot use it in the emacs 24 + Windows 7.
Is there any convenient key to open/find the file in subfolder fast?
thanks.
Personally, I recommend using isearch when you're finding something in a buffer, including dired. I find that the incremental search really help and efficient after I get familiar with it.
You can take a look at 10 Specific Ways to Improve Your Productivity With Emacs. It's tip 4.
As he said:
"It's difficult to overemphasize how powerful this technique is, once you've mastered it."
Your question is not clear to me.
In Dired (including for Dired+), j prompts you for a file name and moves the cursor to that file name in Dired. Does it not do that for you? You say that you cannot use it in Emacs 24 and Windows 7. I use it in Emacs 24 and Windows 7 (and with Dired+) all the time, with no problem.
Please provide more info. What happens when you use j?. What did you expect to happen, and what really happens?
But you speak about "opening" the file. That is not what j does. It is what RET does, when the cursor is on the file name. Does that not work for you?
Perhaps you just want to open a file after being prompted for its name? For that, just use C-x 4 f or C-x C-f.
Not clear. But depending on what you really want, perhaps the answer is here: j, RET, or C-x 4 f.
I think I can understand the question. The platform should not matter.
Pressing j provides the current directory string in the mini-buffer,
making it convenient to write a file-name and tab-complete it. When that
file-name is a sub-directory of the dired directory, one can find files
in that sub-directory.
Now, if a file in that sub-directory is selected and you press RET,
minibuffer informs that mark set, and point stay foot.
I tried C-x C-SPC (pop-global-mark) to see if I would be jumped to
the file found in another buffer, but not so. The mark was set at point.
So this provides no answer but in best case a clarification of the
original question. I could agree it would be nice to be jumped with point on that file in the sub-directory.
I stumbled into this because I wondered what j does in dired mode,
pressing it by mistake.
even though i don't use dired mode,
i just tried dired and j and the mini buffer prompts me the file to open. I use lusty mode for files and buffers. but you can use
open-dribble-file
to open a file from a location

Emacs C-c } command and parentheses-match checking

I am working in Emacs 23, editing LaTeX via AUCTeX. I noticed in emacs that when I press C-c }, I receive the minibuffer message
Scan error: "Unbalanced parentheses", 16026, 16440
Question 1. What exactly is this command doing?
Question(s) 2. More generally, how can I determine what I a given macro is doing? Is there, for example, a universal command that request the keyboard shortcut as an input and outputs a description of the command to which that shortcut is bound? Is there a list of all active keyboard shortcuts?
Question 3. How can I find my unmatched parentheses? The post here recommends the command M-x check-parens, but it availed me nothing, not even a minibuffer message.
The answer to 1 and 2 is to do C-h k C-c } and see what the help buffer tells you. This is one of the features that allows us to call Emacs a self-documenting editor. Don't forget that you can follow the links in the help buffer to both the source code where this function is implemented and to other documentation.
You may also want to use C-h m to see all the key bindings added by the major and minor modes that are currently enabled and C-h ? to see what other interesting help functions there are.
I've never used check-parens specifically, but it does work in my current buffer, which is javascript. I see from its documentation (C-h f check-parens) that it relies on the current syntax table, so perhaps for TeX the syntax table doesn't contain enough information for check-syntax to find the error.

Emacs: help me understand file/buffer management

I've been using emacs for all of my text editing needs for the past three years now. When I'm in a single file, working on code or whatnot, I'm fairly efficient. With two files, I can "C-x b RET" between them and I do fine. However, whenever I need to be working on more than two files at a time, I tend to get lost.
Here are some of the problems that I'd like to work on:
I forget what some of my buffers are called, but I don't understand why C-x C-b splits my window into two buffers and exits the mini buffer. Sure I can switch buffers and choose a buffer to visit, but this feels unintuitive, and leaves me with two buffers open.
When I visit a directory rather than a file, I have a convenient list of all of the files and directories. I usually want to do one of two things with this: 1) Open a single file and never see this buffer again OR 2) Open a bunch of files and never see this buffer again. I don't really know how to do this, as moving the point to a file and hitting return doesn't do either of these things.
I know that my buffers aren't like tabs, but I have an inclination to want to scroll through them to find what I want. I don't know of any key-bindings for this, but I'd like it to be M-n / M-p or the like. Then again, this may be a horribly inefficient way to switch buffers.
When I open interactive help of any kind (for example in ESS), I have a habit of switching back to the buffer I was working in and using C-x 1 to get back to a single buffer. When I do this, however, the help buffer hangs around in my buffer list, further confusing me. I know I can switch to that buffer, kill it, switch back, and then go back to a single buffer, but this seems wrong.
The way I've dealt with this so far involves using a tiling window manager and a few emacs windows in different work-spaces, rather than actually learn the best way to manage a number of files in emacs. I don't necessarily want to change emacs to better fit my needs (although I am open to that if it fits in with what I'm about to say), instead, I'd like to grok the thought process behind handling files/buffers the way that emacs does, and how I can be more efficient with it.
Any answer that would help me understand the correct way, or a more efficient way to manage my buffers or files would be greatly appreciated.
Bind C-x C-b to ibuffer. This is a better buffer listing facility with many advanced features, and its default behaviour is to replace the current buffer with the buffer listing, and then bury the listing when you select a buffer (leaving you with the newly-selected buffer in place of the original one).
You can simply use C-x b to enter your selection in the mini-buffer, of course; however the tab-completion (which is needed to make this a viable option, IMO) does open a new window temporarily, at which point I think you might as well familiarise yourself with something with more features.
Use a instead of RET when selecting from dired. This kills the dired buffer instead of leaving it behind. C-h m in any buffer will show you the help for its major mode (followed by help for the minor modes), and you can read about all the available dired key bindings there.
http://www.emacswiki.org/cgi-bin/wiki/TabBarMode ? (edit: I prefer Rémi's answer for this one, but TabBarMode would give you the visual tab element if you were particularly keen on that.)
q is bound to a 'quit' function in a great many major modes. Generally it buries the buffer rather than killing it, but I certainly find that fine.
To elaborate a little on #1, ibuffer has lots of nice features, and M-x customize-group ibuffer RET will give you some idea of how you can customise it to your liking.
Furthermore, you can filter the buffer list by many criteria (again, use C-h m to see its help page), and then generate a 'group' definition from the current filters, and save your custom filters and groups for future usage.
For example:
/ f ^/var/www/ RET: filter buffer list to show only filenames starting with /var/www/.
/ s Web filters RET: name and save active filter set to your init file.
/ g Web development RET: create a named group from the active filters.
/ S My groups RET: name and save group definitions to your init file.
/ r Web filters RET: invoke the "Web filters" filters.
/ R My groups RET: invoke the "My groups" groups.
RET on a group name to collapse or expand it.
C-k and C-y to kill and yank groups, to re-arrange them.
C-h m for more information...
This way you can have a single Emacs instance running, and create filters and groups for different types of task, and easily switch between them.
I think you will really enjoy Ido for dealing with multiple buffers who's names you can't exactly remember. When you type C-x b it shows a list of open buffers in most used order. As you type some of the characters in a buffer name the list is filtered. The characters you type don't have to be at the begging of the name or contiguous. Using C-f, C-b or left/right arrow keys cycles through the buffer choices.
Also see Smex for Ido like functionality for M-x
Closing windows is done with C-x 0. Intentionally splitting the window is done with C-x 2 for horizontal, C-x 3 for vertical. I love this feature, since it allows me to have test and production code visible at the same time. C-x o takes me to the other window.
I use C-x right (or C-x C-right) and C-x left (or C-x C-right) to go to the next and previous buffer. I don't mind anymore off the few buffer that lay around in Emacs but you could use k in the buffer list to kill the buffer you don't use anymore.
You can also try Iswitchb mode which provides auto-completion for buffer names when you switch buffers via C-x b.
To activate:
M-x iswitchb-mode
Or add to your .emacs file:
(iswitchb-mode)
It is similar to Ido mode for buffer switching but a bit more lightweight.
Also, if you want a more customizable listing of your buffers then use M-x bs-show as an alternative to C-x C-b. In that buffer type ? to get a list of actions you can perform.
I think the number one most useful extension for flipping through buffers is Anything. It lets you start typing part of a buffer (or file!) name and it will figure out what you want. I've rebound C-x b to anything-for-buffers. It makes life so much better.
As always, there are many ways to help you with this; it depends a bit on personal preference what works best, here are some links with explanations:
ibuffer; which is an updated buffer menu (C-x C-b)
ido, which let's you have more powerful autocompletion to switch through buffers. It's a kind-of 'better iswitchb'.
These two are enough for me; but you may also be interested in the tabbar-mode, which gives you rudimentary tabs (like firefox has them).