2010-08-25 14 views
5

Trovo che ci siano due modi per impostare la chiave in emacs: golbal-set-key e define-key. Sono uguali? O ci sono pro/contro tra i due approcci?I due metodi per la mappatura dei tasti in Emacs

(global-set-key (kbd "C-c C-f") 'my-find-file) 
(define-key global-map 
    "\C-ck" 'hello) 

risposta

6

Non c'è effettivamente alcuna differenza, se si guarda alla definizione di global-set-key vedrete:

(define-key (current-global-map) key command) 

E 'possibile che (current-global-map) restituirà una mappa della tastiera che è diverso global-key-map, ma inusuale.

Ora, dal momento che define-key accetta un argomento di una mappa dei tasti, è ovviamente più flessibile del semplice global-set-key. Per i dettagli sulle mappe dei tasti, consulta lo info pages.

2

La differenza è che (global-set-key) o (local-set-key) trovare la mappa globale/locale per voi (prima di chiamare (define-key)).

Modifica È possibile utilizzare M-x describe-function per (global-set-key)

(global-set-key key command) 

Give key a global binding as command. 
command is the command definition to use; usually it is 
a symbol naming an interactively-callable function. 
key is a key sequence; noninteractively, it is a string or vector 
of characters or event types, and non-ASCII characters with codes 
above 127 (such as ISO Latin-1) can be included if you use a vector. 

E per (define-key)

(define-key keymap key def) 

In keymap, define key sequence key as def. 
keymap is a keymap. 

key is a string or a vector of symbols and characters meaning a 
sequence of keystrokes and events. Non-ASCII characters with codes 
above 127 (such as ISO Latin-1) can be included if you use a vector. 
Using [t] for key creates a default definition, which applies to any 
event type that has no other definition in this keymap. 
Problemi correlati