Archive-name: GNU-Emacs-FAQ/part2 ------------------------------------------------------------ If you are viewing this text in a GNU Emacs Buffer, you can type "M-2 C-x $" to get an overview of just the questions. Then, when you want to look at the text of the answers, just type "C-x $". To search for a question numbered XXX, type "M-C-s ^XXX:", followed by a C-r if that doesn't work. Type RET to end the search. If you have w3-mode installed (see question 111), you can visit ftp and HTTP uniform resource locators (URLs) by placing the cursor on the URL and typing M-x w3-follow-url-at-point. The FAQ is posted in five parts; if you are missing a section or would prefer to read the FAQ in a single file, see question 22. ------------------------------------------------------------ Status of Emacs 23: Where does the name "Emacs" come from? Emacs originally was an acronym for Editor MACroS. RMS says he "picked the name Emacs because `E' was not in use as an abbreviation on ITS at the time." The first Emacs was a set of macros written in 1976 at MIT by RMS for the editor TECO (Text Editor and COrrector, originally Tape Editor and COrrector) under ITS on a PDP-10. RMS had already extended TECO with a "real-time" full screen mode with reprogrammable keys. Emacs was started by Guy Steele <gls@east.sun.com> as a project to unify the many divergent TECO command sets and key bindings at MIT, and completed by RMS. Many people have said that TECO code looks a lot like line noise. See alt.lang.teco if you are interested. Someone has written a TECO implementation in Emacs Lisp (to find it, see question 90); it would be an interesting project to run the original TECO Emacs inside of Emacs. For some not-so-serious alternative reasons for Emacs to have that name, check out etc/JOKES (see question 4). 24: What is the latest version of Emacs? Emacs 20.3 is the current version as of this writing. 25: What is different about Emacs 20? To find out what has changed in recent versions, type C-h n (M-x view-emacs-news). The oldest changes are at the bottom of the file, so you might want to read it starting there, rather than at the top. The differences between Emacs versions 18 and 19 was rather dramatic; the introduction of frames, faces, and colors on windowing systems was obvious to even the most casual user. There are differences between Emacs versions 19 and 20 as well, but many are more subtle or harder to find. Among the changes are the inclusion of MULE code for languages that use non-Latin characters, the "customize" facility for modifying variables without having to use Lisp, and automatic conversion of files from Macintosh, Microsoft, and Unix platforms. A number of older Lisp packages, such as Gnus, Supercite and the calendar/diary, have been updated and enhanced to work with Emacs 20, and are now included with the standard distribution. Common Things People Want To Do 26: How do I set up a .emacs file properly? See "Init File" in the on-line manual. WARNING: In general, new Emacs users should not have .emacs files, because it causes confusing non-standard behavior. Then they send questions to help-gnu-emacs asking why Emacs isn't behaving as documented. :-) Emacs 20 includes the new "customize" facility, which can be invoked using M-x customize RET. This allows users who are unfamiliar with Emacs Lisp to modify their .emacs files in a relatively straightforward way, using menus rather than Lisp code. Not all packages support Customize as of this writing, but the number is growing fairly steadily. While Customize might indeed make it easier to configure Emacs, consider taking a bit of time to learn Emacs Lisp and modifying your .emacs directly. Simple configuration options are described rather completely in the "Init File" section of the on-line manual, for users interested in performing frequently requested, basic tasks. 27: How do I debug a .emacs file? Start Emacs with the "-debug-init" command-line option. This enables the Emacs Lisp debugger before evaluating your .emacs file, and places you in the debugger if something goes wrong. The top line in the trace-back buffer will be the error message, and the second or third line of that buffer will display the Lisp code from your .emacs file that caused the problem. You can also evaluate an individual function or argument to a function in your .emacs file by moving the cursor to the end of the function or argument and typing "C-x C-e" (M-x eval-last-sexp). Use "C-h v" (M-x describe-variable) to check the value of variables which you are trying to set or use. 28: How do I make Emacs display the current line (or column) number? To have Emacs automatically display the current line number of the point in the mode line, do "M-x line-number-mode". You can also put the form (setq line-number-mode t) in your .emacs file to achieve this whenever you start Emacs. Note that Emacs will not display the line number if the buffer is larger than the value of the variable line-number-display-limit. As of Emacs 20, you can similarly display the current column with "M-x column-number-mode", or by putting the form (setq column-number-mode t) in your .emacs file. The "%c" format specifier in the variable mode-line-format will insert the current column's value into the mode line. See the documentation for mode-line-format (using "C-h v mode-line-format RET") for more information on how to set and use this variable. Users of all Emacs versions can display the current column using Per Abrahamsen's <abraham@iesd.auc.dk> "column" package. See question 90 for instructions on how to get it. None of the vi emulation modes provide the "set number" capability of vi (as far as we know). 29: How can I modify the titlebar to contain the current filename? The contains of an Emacs frame's titlebar is controlled by the variable frame-title-format, which has the same structure as the variable mode-line-format. (Use "C-h v" or "M-x describe-variable" to get information about one or both of these variables.) By default, the titlebar for a frame does contain the name of the buffer currently being visited, except if there is a single frame. In such a case, the titlebar contains the name of the user and the machine at which Emacs was invoked. This is done by setting frame-title-format to the default value of (multiple-frames "%b" ("" invocation-name "@" system-name)) To modify the behavior such that frame titlebars contain the buffer's name regardless of the number of existing frames, include the following in your .emacs: (setq frame-title-format "%b") 30: How do I turn on abbrevs by default just in mode XXX? Put this in your .emacs file: (condition-case () (quietly-read-abbrev-file) (file-error nil)) (add-hook 'XXX-mode-hook (function (lambda () (setq abbrev-mode t)))) 31: How do I turn on auto-fill mode by default? To turn on auto-fill mode just once for one buffer, use "M-x auto-fill-mode". To turn it on for every buffer in a certain mode, you must use the hook for that mode. For example, to turn on auto-fill mode for all text buffers, including the following in your .emacs file: (add-hook 'text-mode-hook 'turn-on-auto-fill) If you want auto-fill mode on in all major modes, do this: (setq-default auto-fill-function 'do-auto-fill) 32: How do I make Emacs use a certain major mode for certain files? If you want to use XXX mode for all files which end with the extension ".YYY", this will do it for you: (setq auto-mode-alist (cons '("\\.YYY\\'" . XXX-mode) auto-mode-alist)) Otherwise put this somewhere in the first line of any file you want to edit in XXX mode (in the second line, if the first line begins with "#!"): -*-XXX-*- Beginning with Emacs 19, the variable interpreter-mode-alist specifies which mode to use when loading a shell script. (Emacs determines which interpreter you're using by examining the first line of the file.) This feature only applies when the file name doesn't indicate which mode to use. Use "C-h v" (or M-x describe-variable) on interpreter-mode-alist to learn more. 33: How do I search for, delete, or replace unprintable (8-bit or control) characters? To search for a single character that appears in the buffer as, for example, "\237", you can type "C-s C-q 2 3 7". (This assumes the value of search-quote-char is 17 (i.e., `C-q').) Searching for ALL unprintable characters is best done with a regular expression ("regexp") search. The easiest regexp to use for the unprintable chars is the complement of the regexp for the printable chars. Regexp for the printable chars: [\t\n\r\f -~] Regexp for the unprintable chars: [^\t\n\r\f -~] To type these special characters in an interactive argument to isearch-forward-regexp or re-search-forward, you need to use C-q. (`\t', `\n', `\r', and `\f' stand respectively for TAB, LFD, RET, and C-l.) So, to search for unprintable characters using re-search-forward: M-x re-search-forward RET [^ TAB C-q LFD C-q RET C-q C-l SPC -~] RET Using isearch-forward-regexp: M-C-s [^ TAB RET C-q RET C-q C-l SPC -~] To delete all unprintable characters, simply use replace-regexp: M-x replace-regexp RET [^ TAB C-q LFD C-q RET C-q C-l SPC -~] RET RET Replacing is similar to the above. To replace all unprintable characters with a colon, use: M-x replace-regexp RET [^ TAB C-q LFD C-q RET C-q C-l SPC -~] RET : RET NOTE: * You don't need to quote TAB with either isearch or typing something in the minibuffer. 34: How can I highlight a region of text in Emacs? If you are using a windowing system such as X, you can cause the region to be highlighted when the mark is active by including (transient-mark-mode t) in your .emacs file. (Also see question 66.) 35: How do I control Emacs's case-sensitivity when searching/replacing? For searching, the value of the variable case-fold-search determines whether they are case sensitive: (setq case-fold-search nil) ; make searches case sensitive (setq case-fold-search t) ; make searches case insensitive Similarly, for replacing the variable case-replace determines whether replacements preserve case. To change the case sensitivity just for one major mode, use the major mode's hook. For example: (add-hook 'XXX-mode-hook (function (lambda () (setq case-fold-search nil)))) 36: How do I make Emacs wrap words for me? Use auto-fill mode, activated by typing "M-x auto-fill-mode". The default maximum line width is 70, determined by the variable fill-column. To learn how to turn this on automatically, see question 31. 37: Where can I get a better spelling checker for Emacs? Use Ispell. See question 110. 38: How can I spell-check TeX or *roff documents? Use Ispell. See question 110. Ispell can handle TeX and *roff documents. 39: How do I change load-path? In general, you should only *add* to the load-path. You can add directory /XXX/YYY to the load path like this: (setq load-path (cons "/XXX/YYY/" load-path)) To do this relative to your home directory: (setq load-path (cons "~/YYY/" load-path) 40: How do I use an already running Emacs from another window? Emacsclient, which comes with Emacs, is for editing a file using an already running Emacs rather than starting up a new Emacs. It does this by sending a request to the already running Emacs, which must be expecting the request. * Setup Emacs must have executed the "server-start" function for emacsclient to work. This can be done either by a command line option: emacs -f server-start or by invoking server-start from the .emacs file: (if (some conditions are met) (server-start)) When this is done, Emacs starts a subprocess running a program called "server". "server" creates a Unix domain socket in the user's home directory named .emacs_server. To get your news reader, mail reader, etc., to invoke emacsclient, try setting the environment variable EDITOR (or sometimes VISUAL) to the value "emacsclient". You may have to specify the full pathname of the emacsclient program instead. Examples: # csh commands: setenv EDITOR emacsclient setenv EDITOR /usr/local/emacs/etc/emacsclient # using full pathname # sh command: EDITOR=emacsclient ; export EDITOR * Normal use When emacsclient is run, it connects to the ".emacs_server" socket and passes its command line options to "server". When "server" receives these requests, it sends this information on the the Emacs process, which at the next opportunity will visit the files specified. (Line numbers can be specified just like with Emacs.) The user will have to switch to the Emacs window by hand. When the user is done editing a file, the user can type "C-x #" (or M-x server-edit) to indicate this. If there is another buffer requested by emacsclient, Emacs will switch to it; otherwise emacsclient will exit, signaling the calling program to continue. NOTE: "emacsclient" and "server" must be running on machines which share the same filesystem for this to work. The pathnames that emacsclient specifies should be correct for the filesystem that the Emacs process sees. The Emacs process should not be suspended at the time emacsclient is invoked. emacsclient should either be invoked from another X window or from a shell window inside Emacs itself. There is an enhanced version of emacsclient/server called "gnuserv" by Andy Norman <ange@hplb.hpl.hp.com> which is available in the Emacs Lisp Archive (see question 90). Gnuserv uses Internet domain sockets, so it can work across most network connections. It also supports the execution of arbitrary Emacs Lisp forms and does not require the client program to wait for completion. The alpha version of an enhanced version of gnuserv is available at ftp://ftp.wellfleet.com/netman/psmith/emacs/gnuserv-2.1alpha.tar.gz 41: How do I make Emacs recognize my compiler's funny error messages? The variable compilation-error-regexp-alist helps control how Emacs parses your compiler output. It is a list of triples of the form: (REGEXP FILE-IDX LINE-IDX) where REGEXP, FILE-IDX and LINE-IDX are strings. To help determine what the constituent elements should be, load compile.el and then use C-h v compilation-error-regexp-alist RET to see the current value. A good idea is to look at compile.el itself as the comments included for this variable are quite useful -- the regular expressions required for your compiler's output may be very close to one already provided. Once you have determined the proper regexps, use the following to inform Emacs of your changes: (setq compilation-error-regexp-alist (cons '(REGEXP FILE-IDX LINE-IDX) compilation-error-regexp-alist)) 42: How do I indent switch statements like this? Many people want to indent their switch statements like this: f() { switch(x) { case A: x1; break; case B: x2; break; default: x3; } } The solution at first appears to be: set c-indent-level to 4 and c-label-offset to -2. However, this will give you an indentation spacing of four instead of two. The solution is to use cc-mode (the default mode for C programming in Emacs 20) and add the following line: (c-set-offset 'case-label '+) There appears to be no way to do this with the old c-mode. 43: How can I make Emacs automatically scroll horizontally? Use hscroll-mode, included in Emacs 20. Here is some information from the documentation, available by typing C-h f hscroll-mode RET: Automatically scroll horizontally when the point moves off the left or right edge of the window. - Type "M-x hscroll-mode" to enable it in the current buffer. - Type "M-x hscroll-global-mode" to enable it in every buffer. - "turn-on-hscroll" is useful in mode hooks as in: (add-hook 'text-mode-hook 'turn-on-hscroll) - hscroll-margin controls how close the cursor can get to the edge of the window. - hscroll-step-percent controls how far to jump once we decide to do so. 44: How do I make Emacs "typeover" or "overwrite" instead of inserting? M-x overwrite-mode (a minor mode). This toggles overwrite-mode on and off, so exiting from overwrite-mode is as easy as another M-x overwrite-mode. On some workstations, the "Insert" key toggles overwrite-mode on and off. 45: How do I stop Emacs from beeping on a terminal? Martin R. Frank <martin@cc.gatech.edu> writes: Tell Emacs to use the "visible bell" instead of the audible bell, and set the visible bell to nothing. That is, put the following in your TERMCAP environment variable (assuming you have one): ... :vb=: ... And evaluate the following Lisp form: (setq visible-bell t) 46: How do I turn down the bell volume in Emacs running under X Windows? You can adjust the bell volume and duration for all programs with the shell command xset. Invoking xset without any arguments produces some basic information, including the following: usage: xset [-display host:dpy] option ... To turn bell off: -b b off b 0 To set bell volume, pitch and duration: b [vol [pitch [dur]]] b on 47: How do I tell Emacs to automatically indent a new line to the indentation of the previous line? Such behavior is automatic in Emacs 20. From the NEWS file for Emacs 20.2: ** In Text mode, now only blank lines separate paragraphs. This makes it possible to get the full benefit of Adaptive Fill mode in Text mode, and other modes derived from it (such as Mail mode). TAB in Text mode now runs the command indent-relative; this makes a practical difference only when you use indented paragraphs. As a result, the old Indented Text mode is now identical to Text mode, and is an alias for it. If you want spaces at the beginning of a line to start a paragraph, use the new mode, Paragraph Indent Text mode. If you have auto-fill mode on (see question 31), you can tell Emacs to prefix every line with a certain character sequence, the "fill prefix." Type the prefix at the beginning of a line, position point after it, and then type "C-x ." (set-fill-prefix) to set the fill prefix. Thereafter, auto-filling will automatically put the fill prefix at the beginning of new lines, and M-q (fill-paragraph) will maintain any fill prefix when refilling the paragraph. NOTE: If you have paragraphs with different levels of indentation, you will have to set the fill prefix to the correct value each time you move to a new paragraph. To avoid this hassle, try one of the many packages available from the Emacs Lisp Archive (see question 90.) Look up "fill" and "indent" in the Lisp Code Directory for guidance. 48: How do I show which parenthesis matches the one I'm looking at? As of version 19, Emacs comes with paren.el, which (when loaded) will automatically highlight matching parentheses whenever point (i.e., the cursor) is located over one. To load paren automatically, include the line (require 'paren) in your .emacs file. Alan Shutko <shutkoa@ugsolutions.com> reports that as of version 20.1, you must also call show-paren-mode in your .emacs file: (show-paren-mode 1) The "customize" facility will let you turn on show-paren-mode. Use M-x customize-group RET paren-showing RET. From within customize, you can also go directly to the "paren-showing" group. Alternatives to paren include: * If you're looking at a right parenthesis (or brace or bracket) you can delete it and reinsert it. Emacs will blink the cursor on the matching parenthesis. * M-C-f (forward-sexp) and M-C-b (backward-sexp) will skip over one set of balanced parentheses, so you can see which parentheses match. (You can train it to skip over balanced brackets and braces at the same time by modifying the syntax table.) * Here is some Emacs Lisp that will make the % key show the matching parenthesis, like in vi. In addition, if the cursor isn't over a parenthesis, it simply inserts a % like normal. ;; By an unknown contributor (global-set-key "%" 'match-paren) (defun match-paren (arg) "Go to the matching parenthesis if on parenthesis otherwise insert %." (interactive "p") (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1)) ((looking-at "\\s\)") (forward-char 1) (backward-list 1)) (t (self-insert-command (or arg 1))))) 49: In C mode, can I show just the lines that will be left after #ifdef commands are handled by the compiler? M-x hide-ifdef-mode. (This is a minor mode.) You might also want to try cpp.el, available at the Emacs Lisp Archive (see question 90). 50: Is there an equivalent to the `.' (dot) command of vi? (`.' is the redo command in vi. It redoes the last insertion/deletion.) The next version of No, not really, because Emacs doesn't have a special insertion mode. You can type "C-x ESC ESC" (repeat-complex-command) to reinvoke commands that used the minibuffer to get arguments. In repeat-complex-command you can type M-p and M-n to scan through all the different complex commands you've typed. To repeat a set of commands, use keyboard macros. (See "Keyboard Macros" in the on-line manual.) If you're really desperate for the `.' command, use VIPER, which comes with Emacs, and which appears to support it. (See question 107.) 51: What are the valid X resource settings (i.e., stuff in .Xdefaults)? See Emacs man page, or "Resources X" in the on-line manual. You can also use a resource editor, such as editres (for X11R5 and onwards), to look at the resource names for the menu bar, assuming Emacs was compiled with the X toolkit. 52: How do I execute ("evaluate") a piece of Emacs Lisp code? There are a number of ways to execute ("evaluate," in Lisp lingo) an Emacs Lisp "form": * If you want it evaluated every time you run Emacs, put it in a file named ".emacs" in your home directory. This is known as your ".emacs file," and contains all of your personal customizations. * You can type the form in the *scratch* buffer, and then type LFD (or C-j) after it. The result of evaluating the form will be inserted in the buffer. * In Emacs-Lisp mode, typing M-C-x evaluates a top-level form before or around point. * Typing "C-x C-e" in any buffer evaluates the Lisp form immediately before point and prints its value in the echo area. * Typing M-: or M-x eval-expression allows you to type a Lisp form in the minibuffer which will be evaluated. * You can use M-x load-file to have Emacs evaluate all the Lisp forms in a file. (To do this from Lisp use the function "load" instead.) These functions are also useful (see question 16 if you want to learn more about them): load-library, eval-region, eval-current-buffer, require, autoload 53: How do I change Emacs's idea of the tab character's length? Set the variable default-tab-width. For example, to set tab stops every 10 characters, insert the following in your .emacs file: (setq default-tab-width 10) Do not confuse variable tab-width with variable tab-stop-list. The former is used for the display of literal tab characters. The latter controls what characters are inserted when you press the TAB character in certain modes. 54: How do I insert `>' at the beginning of every line? To do this to an entire buffer, type "M-< M-x replace-regexp RET ^ RET > RET". To do this to a region, use "string-rectangle" ("C-x r t"). Set the mark (`C-SPC') at the beginning of the first line you want to prefix, move the cursor to last line to be prefixed, and type "C-x r t > RET". To do this for the whole buffer, type "C-x h C-x r t > RET". If you are trying to prefix a yanked mail message with '>', you might want to set the variable mail-yank-prefix. Better yet, get the Supercite package (see question 105), which provides flexible citation for yanked mail and news messages. 55: How do I insert "_^H" before each character in a region to get an underlined paragraph? M-x underline-region. 56: How do I repeat a command as many times as possible? Use "C-x (" and "C-x )" to make a keyboard macro that invokes the command and then type "M-0 C-x e". WARNING: any messages your command prints in the echo area will be suppressed. 57: How do I make Emacs behave like this: when I go up or down, the cursor should stay in the same column even if the line is too short? M-x picture-mode. 58: How do I tell Emacs to iconify itself? "C-z" iconifies Emacs when running under X Windows and suspends Emacs otherwise. See "Misc X" in the on-line manual. 59: How do I use regexps (regular expressions) in Emacs? See "Regexps" in the on-line manual. WARNING: The "or" operator is `\|', not `|', and the grouping operators are `\(' and `\)'. Also, the string syntax for a backslash is `\\'. To specify a regular expression like xxx\(foo\|bar\) in a Lisp string, use "xxx\\(foo\\|bar\\)" Notice the doubled backslashes! WARNING: Unlike in Unix grep, sed, etc., a complement character set ([^...]) can match a newline character (LFD aka C-j aka \n), unless newline is mentioned as one of the characters not to match. WARNING: The character syntax regexps (e.g., "\sw") are not meaningful inside character set regexps (e.g., "[aeiou]"). (This is actually typical for regexp syntax.) 60: How do I perform a replace operation across more than one file? The "tags" feature of Emacs includes the command tags-query-replace which performs a query-replace across all the files mentioned in the TAGS file. See "Tags Search" in the on-line manual. As of Emacs 19.29, Dired mode ("M-x dired RET", or C-x d) supports the command dired-do-query-replace, which allows users to replace regular expressions in multiple files. 61: Where is the documentation for "etags"? The "etags" man page should be in the same place as the "emacs" man page. Quick command-line switch descriptions are also available. For example, "etags -H". 62: How do I disable backup files? You probably don't want to do this, since backups are useful. To avoid seeing backup files (and other "uninteresting" files) in Dired, load dired-x by adding the following to your .emacs file: (add-hook 'dired-load-hook (function (lambda () (load "dired-x")))) With dired-x loaded, `M-o' toggles omitting in each dired buffer. You can make omitting the default for new dired buffers by putting the following in your .emacs: (setq initial-dired-omit-files-p t) If you're tired of seeing backup files whenever you do an "ls" at the Unix shell, try GNU ls with the "-B" option. GNU ls is part of the GNU fileutils package, available at mirrors of ftp.gnu.org (see question 92). To disable or change how backups are made, see "Backup Names" in the on-line manual. 63: How do I disable auto-save-mode? You probably don't want to do this, since auto-saving is useful, especially when Emacs or your computer crashes while you are editing a document. Instead, you might want to change the variable auto-save-interval, which specifies how many keystrokes Emacs waits before auto-saving. Increasing this value forces Emacs to wait longer between auto-saves, which might annoy you less. You might also want to look into Sebastian Kremer's auto-save package, available from the Lisp Code Archive (see question 90). This package also allows you to place all auto-save files in one directory, such as /tmp. To disable or change how auto-save-mode works, see "Auto Save" in the on-line manual. 64: How can I create or modify new pull-down menu options? Each menu title (e.g., Buffers, File, Edit) represents a local or global keymap. Selecting a menu title with the mouse displays that keymap's non-nil contents in the form of a menu. So to add a menu option to an existing menu, all you have to do is add a new definition to the appropriate keymap. Adding a "forward word" command to the "Edit" menu thus requires the following Lisp code: (define-key global-map [menu-bar edit forward] '("Forward word" . forward-word)) The first line adds the entry to the global keymap, which includes global menu bar entries. Replacing the reference to "global-map" with a local keymap would add this menu option only within a particular mode. The second line describes the path from the menu-bar to the new entry. Placing this menu entry underneath the "File" menu would mean changing the word "edit" in the second line to "file." The third line is a cons cell whose first element is the title that will be displayed, and whose second element is the function that will be called when that menu option is invoked. To add a new menu, rather than a new option to an existing menu, we must define an entirely new keymap: (define-key global-map [menu-bar words] (cons "Words" (make-sparse-keymap "Words"))) The above code creates a new sparse keymap, gives it the name "Words", and attaches it to the global menu bar. Adding the "forward word" command to this new menu would thus require the following code: (define-key global-map [menu-bar words forward] '("Forward word" . forward-word)) Note that because of the way keymaps work, menu options are displayed with the more recently defined items at the top. Thus if you were to define menu options "foo", "bar", and "baz" (in that order), menu option "baz" would appear at the top, and "foo" would be at the bottom. One way to avoid this problem is to use the function define-key-after, which works the same as define-key, but lets you modify where items appear. The following Lisp code would insert the "forward word" function in the "edit" menu immediately following the "undo" option: (define-key-after (lookup-key global-map [menu-bar edit]) [forward] '("Forward word" . forward-word) 'undo) Note how the second and third arguments to define-key-after are different from those of define-key, and that we have added a new (final) argument, the function after which our new key should be defined. To move a menu option from one position to another, simply evaluate define-key-after with the appropriate final argument. More detailed information -- and more examples of how to create and modify menu options -- are in the Emacs Lisp Reference Manual, under "Keymaps." (See question 16 for information on this manual.) 65: How do I delete menus and menu options? The simplest way to remove a menu is to set its keymap to nil. For example, to delete the "Words" menu (from question 64), use: (define-key global-map [menu-bar words] nil) Similarly, removing a menu option requires redefining a keymap entry to nil. For example, to delete the "Forward word" menu option from the "Edit" menu (we added it in question 64), use: (define-key global-map [menu-bar edit forward] nil) 66: How do I turn on syntax highlighting? Font-lock mode is the standard way to have Emacs perform syntax highlighting. With font-lock mode invoked, different types of text will appear in different colors. For instance, if you turn on font-lock in a programming mode, variables will appear in one face, keywords in a second, and comments in a third. Earlier versions of Emacs supported hilit19, a similar package. Use of hilit19 is now considered non-standard, although hilit19.el comes with the stock Emacs distribution. It is no longer maintained. To turn font-lock mode on within an existing buffer, use "M-x font-lock-mode RET". To automatically invoke font-lock mode when a particular major mode is invoked, set the major mode's hook. For example, to fontify all c-mode buffers, add the following to your .emacs file: (add-hook 'c-mode-hook 'turn-on-font-lock) To automatically invoke font-lock mode for all major modes, you can turn on global-font-lock mode by including the following line in your .emacs file: (global-font-lock-mode 1) This instructs Emacs to turn on font-lock mode in those buffers for which a font-lock mode definition has been provided (in the variable font-lock-global-modes). If you edit a file in pie-ala-mode, and no font-lock definitions have been provided for pie-ala files, then the above setting will have no effect on that particular buffer. Highlighting with font-lock mode can take quite a while, and thus different levels of decoration are available, from slight to gaudy. To control how decorated your buffers should become, set the value of font-lock-maximum-decoration in your .emacs file, with a nil value indicating default (usually minimum) decoration, and a t value indicating the maximum decoration. For the gaudiest possible look, then, include the line (setq font-lock-maximum-decoration t) in your .emacs file. You can also set this variable such that different modes are highlighted in a different ways; for more information, see the documentation for font-lock-maximum-decoration with "C-h v" (or "M-x describe-variable RET"). You might also want to investigate fast-lock-mode and lazy-lock-mode, versions of font-lock-mode that speed up highlighting. The advantage of lazy-lock-mode is that it only fontifies buffers when certain conditions are met, such as after a certain amount of idle time, or after you have finished scrolling through text. See the documentation for lazy-lock-mode by typing C-h f lazy-lock-mode ("M-x describe-function RET lazy-lock-mode RET"). Also see the documentation for the function font-lock-mode, available by typing C-h f font-lock-mode ("M-x describe-function RET font-lock-mode RET"). For more information on font-lock mode, take a look at the font-lock mode FAQ, maintained by Jari Aalto <jari.aalto@ntc.nokia.com> at ftp://cs.uta.fi/pub/ssjaaa/ema-font.gui To print buffers with the faces (i.e., colors and fonts) intact, use "M-x ps-print-buffer-with-faces" or "M-x ps-print-region-with-faces". 67: How can I force Emacs to scroll only one line when I move past the bottom of the screen? Place the following Lisp form in your .emacs file: (setq scroll-step 1) Also see "Scrolling" in the on-line manual. 68: How can I replace highlighted text with what I type? Use delete-selection mode, which you can start automatically by placing the following Lisp form in your .emacs file: (delete-selection-mode t) According to the documentation string for delete-selection mode (which you can read using M-x describe-function RET delete-selection-mode RET): When ON, typed text replaces the selection if the selection is active. When OFF, typed text is just inserted at point. This mode also allows you to delete (not kill) the highlighted region by pressing DEL. 69: How can I edit MS-DOS files using Emacs? As of Emacs 20, detection and handling of MS-DOS (and Windows) files is performed transparently. You can open MS-DOS files on a Unix system, edit it, and save it without having to worry about the file format. When editing an MS-DOS style file, a backslash (\) will appear in the mode line. If you are running an earlier version of Emacs, get crypt++ from the Emacs Lisp Archive (see question 90). Among other things, crypt++ transparently modifies MS-DOS files as they are loaded and saved, allowing you to ignore the different conventions that Unix and MS-DOS have for delineating the end of a line. 70: How can I tell Emacs to fill paragraphs with a single space after each period? Ulrich Mueller <ulm@vsnhd1.cern.ch> suggests adding the following two lines to your .emacs file: (setq sentence-end "[.?!][]\"')}]*\\($\\|[ \t]\\)[ \t\n]*") (setq sentence-end-double-space nil)
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |