📄 faq
字号:
file: /pub/gnu/emacs/ps-emacs.tar.Z Binding Keys to Commands33: Why does my key binding fail? Most likely, it failed because "ESC [" was already defined. Evaluate this form first: (define-key esc-map "[" nil) 34: Why doesn't this [terminal or window-system setup] code work in my .emacs file, but it works just fine after Emacs starts up? This is because you're trying to do something in your .emacs file that needs to be postponed until after the terminal/window-system setup code is loaded. This is a result of the order in which things are done during the startup of Emacs. In order to postpone the execution of Emacs Lisp code until after the terminal/window-system setup, set the value of the variable term-setup-hook or window-setup-hook to be a function which does what you want. See question 72 for a complete explanation of what Emacs does every time it is started. Here is a simple example of how to set term-setup-hook: (setq term-setup-hook (function (lambda () (if (string-match "^vt220" (or (getenv "TERM") "")) ;; Make vt220's "Do" key behave like M-x: (define-key CSI-map "29~" 'execute-extended-command))))) 35: How do I use function keys under X Windows? If compiled on a Sun, Emacs recognizes the function keys that are normally on a Sun keyboard, and you can bind them the same way you normally bind Sun keys. Each function key will generate a key sequence that looks like "ESC [ ### z", where ### is replaced by a number. If not compiled on a Sun, the function keys will appear to Emacs in a way remarkably similar to the keys of a VT220 terminal. Each function key will generate a key sequence that looks like "ESC [ ### ~". For the complete list of the numbers which are generated by the function keys, look in the file src/x11term.c. However, this may be inadequate for you if you have function keys Emacs doesn't know about. Johan Vromans <jv@mh.nl> explains: There are a number of tricks that can be helpful. The most elegant solution, however, is to use the function "x-rebind-key". This function is commented out in the source for good reasons --- it's buggy. It is rather easy to replace this function with the function epoch:rebind-key from the Epoch distribution. After implementing this, all keyboard keys can be configured to send user definable sequences, e.g. (x-rebind-key "KP_F1" 0 "\033OP") This will have the keypad key PF1 send the sequence \eOP, just like an ordinary VTxxx terminal. Another method is to handle the keys in the C source. Although this may be slightly more efficient, it is much less flexible. Finally, some people have established a convention to have the special keys send a sequence of characters that indicate the key and its modifiers instead of a plain escape sequence. This is also a good method. The advantage of sending the plain escape sequences is that you require only one setup for Emacs running under X and on normal terminals, e.g. (x-rebind-key "KP_F1" 0 "\033OP") will have key PF1 send \eOP, and, probably in another setup file: (global-set-key "\eOP" 'specific-function) to bind PF1 to a function. The last statement applies for normal VTxxx terminal also. 36: How do I tell what characters my function keys emit? Use this function by Randal L. Schwartz <merlyn@iwarp.intel.com>: (defun see-chars () "Displays characters typed, terminated by a 3-second timeout." (interactive) (let ((chars "") (inhibit-quit t)) (message "Enter characters, terminated by 3-second timeout.") (while (not (sit-for 3)) (setq chars (concat chars (list (read-char))) quit-flag nil)) ; quit-flag maybe set by C-g (message "Characters entered: %s" (key-description chars)))) Problems with Key Bindings and Input37: 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. WARNING: the value of C-g (7) is hard coded in several places both before and after the translation specified by keyboard-translate-table is carried out. Thus, swapping C-g with another key may cause problems; rebinding C-g may also cause problems. (Well, I've never done it, so I don't know for sure.) (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 <warsaw@cme.nist.gov> 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: Why does Emacs crash under SunOS 4.1? Under SunOS 4.1, Emacs dies with this message: Fatal error (6).Abort There is a bug in the "localtime" routine supplied with SunOS 4.1. A private function called by tzsetwall zeroes the byte just past an eight byte region it mallocs. This corrupts GNU malloc's memory pool. Put "#define SYSTEM_MALLOC" in src/config.h. Or, for the purists: Put "#define SUNOS_LOCALTIME_BUG" in src/config.h and apply the following patch to src/malloc.c. (Patch by Eirik Fuller <eirik@elf.tn.cornell.edu>.) >*** malloc.c~ Fri Apr 7 22:12:10 1989 >--- malloc.c Tue May 8 07:07:22 1990 >*************** >*** 476,482 **** >--- 476,487 ---- > multiple of 8, then figure out which nestf[] area to use. > Both the beginning of the header and the beginning of the > block should be on an eight byte boundary. */ >+ #ifdef SUNOS_LOCALTIME_BUG >+ /* SunOS 4.1 localtime scribbles on the ninth byte. */ >+ nbytes = (n + ((sizeof *p + 15) & ~15) + EXTRA + 15) & ~15; >+ #else > nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7; >+ #endif > { > register unsigned int shiftr = (nbytes - 1) >> 2; > 46: Why does Emacs occasionally cause segmentation faults and machine panics on my DECstation 3100? Bruce Cole <cole@dip.cs.wisc.edu> writes: > We're running Emacs 18.54 on an Ultrix Risc DECsystem 5400. Three > times we've had the machine hang with the following message: > > panic: tblmod on invalid pte > > Ultrix support tells us this is caused by Emacs. Has anyone > experienced this? DEC says it only happens on RISC boxes. This is due to a MIPS specific Ultrix kernel bug. I sent DEC a description of the bug with a bug fix. The Kernel bug manifests itself with Emacs since Emacs uses a non-standard data start address on Ultrix MIPS machines. I haven't often seen Emacs cause MIPS machines to panic. Usually you just see one of the following errors when you try to start up Emacs: segmentation fault (core dumped) emacs: Bad address Out of memory data size rlimit exceeded, pid 6523, process tcsh (for example) Until DEC fixes their kernel, you can avoid the bug by changing the data start address used by Emacs. > I have built two newer versions of GNU Emacs and it still happens. I > should also mention that these faults happen quite rarely to some > users (I may see it once a month), while other users see it a few > times a week or even daily! The problem only occurs when a MIPS machine is doing a lot of paging. Users who don't cause their workstation to page will not see this problem. Patch to GNU Emacs 18.55: >*** m-pmax.h Thu Jun 8 11:53:55 1989 >--- m-pmax.h.new Mon Jul 9 10:21:21 1990 >*************** >*** 1,3 **** >--- 1,7 ---- > #include "m-mips.h" > #undef LIBS_MACHINE > #undef BIG_ENDIAN >+ #undef LD_SWITCH_MACHINE >+ #undef DATA_START >+ #define DATA_START 0x10000000 >+ #define DATA_SEG_BITS 0x10000000 47: How do I get Emacs running on VMS under DECwindows? Hal R. Brand <BRAND@addvax.llnl.gov> 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: site: addvax.llnl.gov Johan Vromans <jv@mh.nl> writes: Getting Emacs to run on VMS with DECwindows requires a number of changes
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -