From: CRDGW2::CRDGW2::MRGATE::"SMTP::AI.MIT.EDU::GNULISTS" 26-FEB-1991 05:54:43.01 To: ARISIA::EVERHART CC: Subj: GNU Emacs Frequently Asked Questions with Answers (part 2 of 2) From: gnulists@ai.mit.edu@SMTP@CRDGW2 To: Everhart@Arisia@MRGATE Received: by crdgw1.ge.com (5.57/GE 1.83) id AA03647; Tue, 26 Feb 91 05:49:21 EST Received: by life.ai.mit.edu (4.1/AI-4.10) id AA06244; Sun, 24 Feb 91 14:30:21 EST Return-Path: Received: from wheat-chex (wheat-chex.ai.mit.edu) by life.ai.mit.edu (4.1/AI-4.10) id AA06197; Sun, 24 Feb 91 14:27:45 EST Received: by wheat-chex (4.1/AI-4.10) id AA20593; Sun, 24 Feb 91 14:27:45 EST Resent-Date: 17 Feb 91 22:46:17 GMT Resent-From: gnulists@ai.mit.edu Resent-Message-Id: <9102241927.AA20593@wheat-chex> Received: from tut.cis.ohio-state.edu by life.ai.mit.edu (4.1/AI-4.10) id AA25462; Sun, 17 Feb 91 18:01:39 EST Received: by tut.cis.ohio-state.edu (5.61-kk/5.910130) id AA15552; Sun, 17 Feb 91 17:58:11 -0500 Received: from USENET by tut.cis.ohio-state.edu with netnews for help-gnu-emacs@prep.ai.mit.edu (help-gnu-emacs@prep.ai.mit.edu) (contact usenet@tut.cis.ohio-state.edu if you have questions) Date: 17 Feb 91 22:46:17 GMT From: nntp-read!jbw@bu.edu (Joe Wells) Sender: gnulists@ai.mit.edu Organization: Boston University Computer Science Department Subject: GNU Emacs Frequently Asked Questions with Answers (part 2 of 2) Message-Id: To: help-gnu-emacs@prep.ai.mit.edu GNU Emacs Frequently Asked Questions with Answers (part 2 of 2) Sun Feb 17 17:45:14 1991 Problems with Key Bindings and Input 37: Why does Emacs spontaneously go into "I-search:" mode? Your terminal (or something between your terminal and the computer) is sending C-s and C-q for flow control, and Emacs is receiving these characters and interpreting them as commands. (The C-s character normally invokes the isearch-forward command.) For a more detailed discussion, read the file PROBLEMS in the Emacs distribution. 38: What do I do if my terminal is sending C-s and C-q for flow control and I can't disable it? Use this piece of Emacs Lisp: (set-input-mode nil t) 39: How do I make Emacs use C-s and C-q for flow control instead of for commands? Same answer as previous question. 40: How do I use commands bound to C-s and C-q (or any key) if these keys are filtered out? I suggest swapping C-s with C-\ and C-q with C-^: (swap-keys ?\C-s ?\C-\\) (swap-keys ?\C-q ?\C-^) See question 41 for the implementation of swap-keys. 41: How do I "swap" two keys? When Emacs receives a character, you can make Emacs behave as though it received another character by setting the value of keyboard-translate-table. The following Emacs Lisp will do this for you, allowing you to "swap" keys. After arranging for this Lisp to be evaluated by Emacs, you can evaluate "(swap-keys ?A ?B)" to swap A and B. WARNING: the value of C-g (7) is still hard coded in one place in the minibuffer code. Thus, swapping C-g with another key may cause minor problems. (defun swap-keys (key1 key2) "Swap keys KEY1 and KEY2 using map-key." (map-key key1 key2 t) (map-key key2 key1)) (defvar map-keys-alist nil "Association list of key mappings currently in effect. If (FROM . TO) is an element, that means key FROM is currently mapped to TO.") (defun map-key (from to &optional no-update) "Make key FROM behave as though key TO was typed instead. If optional argument NO-UPDATE is non-nil, the key-mapping does not take effect until a subsequent map-key or unmap-key." (let ((alist-entry (assq from map-keys-alist))) (if alist-entry (setcdr alist-entry to) (setq map-keys-alist (cons (cons from to) map-keys-alist)))) (or no-update (map-keys-update))) (defun unmap-key (key) "Undo any mapping of key KEY." (setq map-keys-alist (delq (assq key map-keys-alist) map-keys-alist)) (map-keys-update)) ;; Makes keyboard-translate-table reflect the key mappings in ;; map-keys-alist. (defun map-keys-update () (if (null map-keys-alist) ;; Emacs runs fasted if keyboard-translate-table is nil (setq keyboard-translate-table nil) (let ((max-key-mapped ;; Find the mapped key with largest value (apply 'max (mapcar (function (lambda (x) (car x))) map-keys-alist))) (i 0)) ;; keyboard-translate-table doesn't have to be any longer than ;; necessary. This speeds up Emacs. (setq keyboard-translate-table (make-string (1+ max-key-mapped) 0)) (while (<= i max-key-mapped) (aset keyboard-translate-table i (or (cdr (assq i map-keys-alist)) i)) (setq i (1+ i)))))) 42: Why does the "Backspace" key invoke help? The Backspace key (on every keyboard I've used) sends ASCII code 8. C-h sends the same code. In Emacs by default C-h invokes "help-command". The easiest solution to this problem is to use C-h (and Backspace) for help and DEL (the Delete key) for deleting the previous character. For some people this solution may be problematic: 1. They normally use Backspace outside of Emacs for deleting the previous character typed. This can be solved by making DEL be the command for deleting the previous character outside of Emacs. This command will do this on many Unix systems: stty erase ^? 2. The person may prefer using the Backspace key for deleting the previous character because it is more conveniently located on their keyboard or because they don't even have a separate Delete key. In this case, the best solution is to swap C-h and DEL: (swap-keys ?\C-h ?\C-?) See question 41 for the implementation of swap-keys. 43: How do I type DEL on PC terminal emulators? Someone whose name I forgot wrote: Most PCs have deficient keyboards that don't have both Backspace and Delete keys. Whether C-h (backspace) or DEL is generated by the "Backspace" key varies from one terminal emulator to another. If you're lucky, you can reconfigure the keyboard so that it generates DEL. If not, you will have to hunt to figure out what keystroke will do it --- possibilities include various shifted and controlled versions of "Backspace", the "Del" key on the numeric keypad (which might depend on "Shift" or "NumLock"), or perhaps C-? (Control-?). If this is too hard, you may want to swap the delete key with some other key. See question 42. Building/Installing/Porting Emacs and Machine/OS-Specific Bugs: 44: Why do I get an "f68881_used undefined" error, when I build Emacs on my Sun 3? Barry A. Warsaw writes: Some of the code that is being linked on the "ld" line of emacs' build command has been compiled with the -f68881 option. Most common reason is that you're linking with X libraries which were built with -f68881 option set. You need to either remove all dependencies to the 68881 (may mean a recompile of the X libraries with -fswitch or -fsoft option), or you need to link emacs with the 68881 startup file /usr/lib/Mcrt1.o. Make this change to src/ymakefile: change: #define START_FILES crt0.o to: #define START_FILES crt0.o /usr/lib/Mcrt1.o The order of these start files is critical. 45: How do I get Emacs running on VMS under DECwindows? Hal R. Brand is said to have a VMS save set with a ready-to-run VMS version of Emacs for X Windows. It is available via anonymous FTP (addvax.llnl.gov). Johan Vromans writes: Getting Emacs to run on VMS with DECwindows requires a number of changes to the sources. Fortunately this has been done already. Joshua Marantz did most of the work for Emacs 18.52, and the mods were ported to 18.55 by Johan Vromans . Also included is the handling of DEC's LK201 keyboard. You need to apply the changes to a fresh Emacs 18.55 distribution on a Unix system, and then you can copy the sources to VMS to perform the compile/link/build. The set of changes have been posted a number of times three times the last 12 months, so they should be widely available. 46: What should I do if I have trouble building Emacs? RMS writes: If you try to build Emacs and it does not run, the first thing to do is look in the file called PROBLEMS to see if a solution is given there. If none is given, then please send a report by mail to bug-gnu-emacs@prep.ai.mit.edu. Please do not send it to help-gnu-emacs@prep.ai.mit.edu. Sending to help-gnu-emacs (which has the effect of posting on gnu.emacs.help) is undesirable because it takes the time of an unnecessarily large group of people, most of whom are just users and have no idea how to fix these problem. bug-gnu-emacs reaches a much smaller group of people who are more likely to know what to do and have expressed a wish to receive more messages about Emacs than the others. Weird/Confusing Problems: 47: Does Emacs have problems with files larger than 8 Megs? Most installed versions of GNU Emacs will use 24 bit signed integers (and 24 bit pointers!) internally. This limits the file size that Emacs can handle to 8388608 bytes. Leonard N. Zubkoff writes: Putting the following two lines in src/config.h before compiling Emacs allows for 26 bit integers and pointers: #define VALBITS 26 #define GCTYPEBITS 5 See question 48 for an explanation. 48: Why does Emacs use 24 bit integers and pointers? David Gillespie writes: Emacs is largely written in a dialect of Lisp; Lisp is a freely-typed language in the sense that you can put any value of any type into any variable, or return it from a function, and so on. So each value must carry a "tag" along with it identifying what kind of thing it is, e.g., integer, pointer to a list, pointer to an editing buffer, and so on. Emacs uses standard 32-bit integers for data objects, taking the top 8 bits for the tag and the bottom 24 bits for the value. So integers (and pointers) are somewhat restricted compared to true C integers and pointers. Emacs uses 8-bit tags because that's a little faster on byte-oriented machines, but there are only really enough tags to require 6 bits. See question 47 to find how to recompile Emacs with 6-bit tags and 26-bit integers and pointers if space is at a premium for you. 49: Why does Emacs start up using the wrong directory? Most likely, you have an environment variable named PWD that is set to a value other than the name of your current directory. This is most likely caused by using two different shell programs. "ksh" and (some versions of) "csh" set and maintain the value of the PWD environment variable, but "sh" doesn't. If you start sh from ksh, change your current directory inside sh, and then start Emacs from inside sh, PWD will have the wrong value but Emacs will use this value. See the etc/OPTIONS file for more details. 50: How do I edit a file with a "$" in its name? When entering a filename in the minibuffer, Emacs will attempt to expand a "$" followed by a word as an environment variable. To suppress this behavior, type "$$" instead. 51: Why does Shell Mode lose track of the shell's current directory? Emacs has no way of knowing when the shell actually changes its directory. So it tries to guess by recognizing cd commands. A number of fixes and enhancements to Shell Mode have been written, check the Emacs Lisp Archive (question 14). 52: Why doesn't Emacs expand my aliases when sending mail? First, you must separate multiple addresses with commas. Second, Emacs normally only reads the ".mailrc" file once per session, when you start to compose your first mail message. If you edit .mailrc, you can type "M-ESC (build-mail-aliases) RET" to make Emacs reread .mailrc. 53: Why doesn't setting default-directory always work? There is a separate value of default-directory for each Emacs buffer. The value in the current buffer is the one that is used. 54: Why doesn't my change to load-path work? If you added file names with tildes (~) in them to your load-path, you'll need to do something like this: (setq load-path (mapcar 'expand-file-name load-path)) 55: Why does the cursor always go to the wrong column when I move up or down one line? You have inadvertently typed "C-x C-n" (set-goal-column) which sets the "goal-column" to the column where the cursor was. To undo this type "C-u C-x C-n". If you make this mistake frequently, you might want to unbind this command by doing one of these two: (define-key ctl-x-map "\C-n" nil) (put 'set-goal-column 'disabled t) 56: Why does Emacs hang with message "Unknown XMenu" with X11R4? Many different X errors can produce this message. Here is the solution to one problem: X11 Release 4 now enforces some conditions in the X protocol that were previously allowed to pass unnoticed. You need to put the X11R4 server into X11R3 bug compatibility mode for Emacs's Xmenu code to work. You can do this with the command "xset bc". 57: Why doesn't display-time show the load average in the mode line anymore? In GNU Emacs 18.56, a change was made in the display-time code. Formerly, in version 18.55, Emacs used a program named "loadst" to notify Emacs of the change in time every minute. loadst also sent Emacs the system load average if it was installed with sufficient privelege to get that information (or was on a system where no such privelege was needed). Emacs then displayed this information in the mode line. In version 18.56, this code was changed to use a program named "wakeup". wakeup doesn't send Emacs any information, it's only purpose is to send Emacs *something* every minute, thus invoking the filter function in Emacs once a minute. The filter function in Emacs does all the work of finding the time, date, and load average. However, getting the load average requires the privelege to read kernel memory on most systems. Since giving Emacs this privelege would destroy any security a system might have, for almost everyone this is not an option. In addition, Emacs does not have the code built into it to get this information on the systems which have special system calls for this purpose, even though loadst had code for this. The solution I use is to get the files lisp/display-time.el and etc/loadst.c from version 18.55 and use those with 18.57. WARNING: Do not install Emacs setgid kmem unless you wish to destroy any security your system might have!!!!!!!!!! If you are using Emacs 18.55 or earlier, or the solution I describe above, read further: The most likely cause of the problem is that "loadst" can't read the special file /dev/kmem. To properly install loadst, it should be either setuid to the owner of /dev/kmem, or is should be setgid to the group to which /dev/kmem belongs. In either case, /dev/kmem should be readable by its owner or its group, respectively. Another possibility is that your version of Unix doesn't have the load average data available in /dev/kmem. Your version of Unix might have a special system call to retrieve this information (eg., inq_stats under UMAX), and loadst might not have been enhanced to cope with this. 58: Why doesn't GNUS work anymore via NNTP? There is a bug in NNTP version 1.5.10, such that when multiple requests are sent to the NNTP server, the server only handles the first one before blocking waiting for more input which never comes. NNTP version 1.5.11 claims to fix this. You can work around the bug inside Emacs like this: (setq nntp-maximum-request 1) (setq nntp-buggy-select t) I also have a patch for NNTP 1.5.10 that is based on the timeout code that was in 1.5.9. However, please try to upgrade to 1.5.11 first. 59: Why does ispell sometimes ignore the local dictionary? You need to update the version of ispell to 2.0.02. A patch is available via anonymous FTP (tut.cis.ohio-state.edu:/pub/gnu/ispell/patch2.Z). You also need to change a line in ispell.el from: (defconst ispell-version "2.0.01") ;; Check against output of "ispell -v". to: (defconst ispell-version "2.0.02") ;; Check against output of "ispell -v". Configuring Emacs for yourself: 60: How do I set up a .emacs file properly? See the section of the manual on the .emacs file, inside the section on customization. To reach this section of the online Info manual, type this: C-h i m emacs RET g init SPC file RET 61: How do you debug a .emacs file? First start Emacs with the "-q" command line option. Then, in the *scratch* buffer, type the following: (setq debug-on-error t) C-j (load-file "~/.emacs") C-j (C-j stands for Control-J, ie., hold the control key and press J.) If you have an error in your .emacs file, this will invoke the debugger when the error occurs. If you don't know how to use the debugger do (setq stack-trace-on-error t) instead. WARNING: this will not discover errors caused by trying to do something that requires the terminal/window-system initialization code to have been loaded. See question 34. 62: How do I turn on abbrevs by default just in mode XXX? Put this in your .emacs file: (condition-case () (read-abbrev-file nil t) (file-error nil)) (setq XXX-mode-hook (function (lambda () (setq abbrev-mode t)))) 63: What are the valid X resource settings (ie., stuff in .Xdefaults file)? See the Emacs man page, or the etc/OPTIONS file. 64: How do I turn down the bell volume in Emacs running under X Windows? Under Epoch you can do: (setq epoch::bell-volume 20) Under normal GNU Emacs you must modify the XTfeep function in src/x11term.c, and change the number 50 to some other number: XTfeep () { BLOCK_INPUT_DECLARE (); #ifdef XDEBUG fprintf (stderr, "XTfeep\n"); #endif BLOCK_INPUT (); XBell (XXdisplay,50); /* change this 50 */ UNBLOCK_INPUT (); } 65: How do I make Emacs send 8-bit characters to my terminal? Johan Widen writes: A patch for emacs-18.55 is available by ftp and mail-server from sics.se. Anonymous FTP: site: sics.se [192.16.123.90] file: archive/emacs-18.55-8bit-diff E-mail: To: mail-server@sics.se body: send emacs-18.55-8bit-diff Emacs Lisp programming: 66: What dialect of Lisp is Emacs Lisp? It's the dialect of Lisp called Emacs Lisp. (No joke!) People also call it elisp or e-lisp. (NOTE: The term "Elisp" is trademarked by someone else.) 67: How close is Emacs Lisp to Common Lisp? Pretty far. GNU Emacs Lisp is case-sensitive, uses dynamic scoping, doesn't have packages, doesn't have multiple return values, doesn't have reader macros, etc. For people used to Common Lisp, some of the functions in Common Lisp that are not in Emacs Lisp by default are provided in the file lisp/cl.el. There is a Texinfo manual describing these functions in man/cl.texinfo. 68: How do I execute a piece of Emacs Lisp code? There are a number of ways to execute (called "evaluate") 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. * You can type the form in the "*scratch*" buffer, and then type C-j after it. The result of evaluating the form will be inserted in the buffer. * In 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-ESC 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.) 69: How do I make a set of operations fully local to a region? Use narrow-to-region inside of save-restriction. 70: How can I highlight a region? There are ways to get highlighting in GNU Emacs 18.57, but they all require patching the C code of Emacs and rebuilding. They are also slow and the highlighting disappears if you scroll or redraw the screen. One patch is by Kenichi Handa . You can highlight regions in a variety of ways in Epoch. GNU Emacs 19 will have everything you need, but won't be out soon. 71: How do I change Emacs's idea of the tab character's length? Example: (setq default-tab-width 10). 72: What is the difference between (interactive "P") and (interactive "p")? The value that is a result of "P" can be a list, a symbol, or an integer; the value that is a result of "p" is always an integer: Prefix keys typed result of: "P" "p" nothing nil 1 "M-1" 1 1 "C-u 1" 1 1 "M--" '- -1 "C-u -" '- -1 "C-u" (4) 4 "C-u C-u" (16) 16 Carrying Out Common Tasks: 73: How do I insert ">"'s in the beginning of every line in a buffer? Type "M-x replace-regexp RET ^ RET > RET". ("replace-regexp" can be shortened to "repl TAB r".) To do this only in the region, type "C-x n M-x replace-regexp RET ^ RET > RET C-x w". (You're going to remember that, right?) 74: How do I insert "_^H" characters before each character in a paragraph to get an underlined paragraph? M-x underline-region. 75: How do I repeat a command as many times as possible? 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. 76: How do I search for an unprintable (8-bit) character that appears in a buffer as \237? C-s C-q 2 3 7 (This assumes the value of search-quote-char is 17 (C-q).) 77: How do I control Emacs's case sensitivitiy 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. 78: How do I tell Emacs to automatically indent a new line to the indentation of the previous line? M-x indented-text-mode. (This is a major mode.) If you have auto-fill mode on (minor mode), 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. 79: How do I make Emacs "typeover" or "overwrite" when I type instead of always inserting? M-x overwrite-mode (minor mode). WARNING: delete-backward-char (usually the delete key) doesn't work properly in overwrite mode. It deletes the character to the left, rather than replacing it with a space. 80: How do I show which parenthesis matches the one I'm looking at? 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 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 parenthese, like in vi. In addition, if the cursor isn't over a parenthese, 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 "[([{]") (forward-sexp 1) (backward-char)) ((looking-at "[])}]") (forward-char) (backward-sexp 1)) (t (self-insert-command (or arg 1))))) 81: 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. (This is a minor mode, in theory anyway ...) 82: How do I read news under Emacs? There are at least three news reading packages that operate inside Emacs. "rnews" comes with Emacs. "GNUS" and "Gnews" come separately. {I've never used rnews; could someone write a description? BTW, rnews will be replaced with GNUS in Emacs 19.} Both GNUS and Gnews handle reading news over NNTP. I think both can also read from a local news spool. GNUS also supports reading mail stored in MH folders or articles saved by GNUS. GNUS is written (mostly) by Masanobu Umeda. His {?} latest e-mail address was umerin@tc.nagasaki.go.jp, but I don't think he has an e-mail address right now. The latest version is GNUS 3.13. There is a newsgroup for discussion of GNUS called gnu.emacs.gnus. This newsgroup is gatewayed with the mailing list info-gnus-english to subscribe send mail to info-gnus-english-request@cis.ohio-state.edu. There is also a mailing list called info-gnus, which includes discussion in Japanese. Gnews was written by Matthew Wiener . {Could someone tell me the # of the latest version, and how long it has been since anyone has heard from Matthew?}. There is a newsgroup for Gnews called gnu.emacs.gnews. 83: 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 may have to (load "hideif") first. If you want to do this regularly, put this in your .emacs file: (autoload 'hide-ifdef-mode "hideif" nil t) {Yes, I know, this should be in lisp/loaddefs.el already.} 84: Is there an equivalent to the "." (dot) command of vi? ("." is the redo command in vi. It redoes the last insertion/deletion.) No, not really. You can type "C-x 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 something on each line I recommend using keyboard macros. 85: How do I use emacstool under SunView? The file etc/SUN-SUPPORT includes the document "Using Emacstool with GNU Emacs". Also read the man page for emacstool (etc/emacstool.1). 86: How do I get Emacs to display the current line number on the mode line? There is no "correct" way to constantly display the current line number on the mode line in Emacs 18. Emacs is not a line-oriented editor, and really has no idea what "lines" of the buffer are displayed in the window. It would require a lot of work at the C code level to make Emacs keep track of this. Emacs 19 will probably be able to do this, but probably not with great efficiency. To find out what line of the buffer you are on right now, do "M-x what-line". Typing "C-x l" will also tell you what line you are on, provided the buffer isn't separated into "pages" with C-l characters. In that case, it will only tell you what line of the current "page" you are on. WARNING: "C-x l" gives the wrong value when point is at the beginning of a line. People have written various kludges to display the current line number on the mode line. Look in the Lisp Code Directory. (See question 13.) 87: How do I tell Emacs to iconify itself? You need to modify C source and recompile. Either that or get Epoch instead. For the interested I have a patch to allow Emacs to iconify itself. 88: How do I use regexps (regular expressions) in Emacs? This is documented in the Emacs manual. To read the manual section online, type "C-h i m emacs RET m regexps RET". WARNING: Unlike in Unix grep, sed, etc., a complement character set ([^...]) can match a Newline, unless Newline is mentioned as one of the characters not to match.