Domanda

ho cercato insegnare a me stesso Emacs, e perché sto usando Dvorak, io stupidamente rimbalzo C-c ad un tasto di movimento e siamo abituati. Ora sto davvero iniziando a fare un po 'di programmazione con esso, e ho caricato un file python e ho notato che C-c è il prefisso per tutti i comandi speciali in python-mode.

Posso associare nuovamente la chiave prefisso e modificare tutti i comandi di pitone in un colpo solo nel mio file init.el? In caso contrario, dovrei associare nuovamente tutti i comandi di pitone singolarmente?

È stato utile?

Soluzione

Se si guarda il codice sorgente per python.el, vedrete che i comandi sono stati aggiunti singolarmente utilizzando la specifica completa, per esempio (define-key map "\C-c\C-r" 'python-send-region).

Quindi, si sta andando ad avere per rifarli tutto da soli. Detto questo è piuttosto straight-forward. Dal tuo commento, si desidera cambiare la chiave prefisso da C - ', e il trucco per ottenere la fuga giusta è di non usare sfugge a tutti, ma invece di utilizzare la kbd macro ( link alla documentazione ).

Con questo, è possibile aggiornare la definizione modalità-map di essere:

(defvar python-mode-map
  (let ((map (make-sparse-keymap)))
    ;; Mostly taken from python-mode.el.
    (define-key map ":" 'python-electric-colon)
    (define-key map "\177" 'python-backspace)
    (define-key map (kbd "C-' <") 'python-shift-left)
    (define-key map (kbd "C-' >") 'python-shift-right)
    (define-key map (kbd "C-' C-k") 'python-mark-block)
    (define-key map (kbd "C-' C-d") 'python-pdbtrack-toggle-stack-tracking)
    (define-key map (kbd "C-' C-n") 'python-next-statement)
    (define-key map (kbd "C-' C-p") 'python-previous-statement)
    (define-key map (kbd "C-' C-u") 'python-beginning-of-block)
    (define-key map (kbd "C-' C-f") 'python-describe-symbol)
    (define-key map (kbd "C-' C-w") 'python-check)
    (define-key map (kbd "C-' C-v") 'python-check) ; a la sgml-mode
    (define-key map (kbd "C-' C-s") 'python-send-string)
    (define-key map (kbd "C-\\ M-x") 'python-send-defun)
    (define-key map (kbd "C-' C-r") 'python-send-region)
    (define-key map (kbd "C-' M-r") 'python-send-region-and-go)
    (define-key map (kbd "C-' C-c") 'python-send-buffer)
    (define-key map (kbd "C-' C-z") 'python-switch-to-python)
    (define-key map (kbd "C-' C-m") 'python-load-file)
    (define-key map (kbd "C-' C-l") 'python-load-file) ; a la cmuscheme
    (substitute-key-definition 'complete-symbol 'symbol-complete
                               map global-map)
    (define-key map (kbd "C-' C-i") 'python-find-imports)
    (define-key map (kbd "C-' C-t") 'python-expand-template)
    (easy-menu-define python-menu map "Python Mode menu"
      `("Python"
        :help "Python-specific Features"
        ["Shift region left" python-shift-left :active mark-active
         :help "Shift by a single indentation step"]
        ["Shift region right" python-shift-right :active mark-active
         :help "Shift by a single indentation step"]
        "-"
        ["Mark block" python-mark-block
         :help "Mark innermost block around point"]
        ["Mark def/class" mark-defun
         :help "Mark innermost definition around point"]
        "-"
        ["Start of block" python-beginning-of-block
         :help "Go to start of innermost definition around point"]
        ["End of block" python-end-of-block
         :help "Go to end of innermost definition around point"]
        ["Start of def/class" beginning-of-defun
         :help "Go to start of innermost definition around point"]
        ["End of def/class" end-of-defun
         :help "Go to end of innermost definition around point"]
        "-"
        ("Templates..."
         :help "Expand templates for compound statements"
         :filter (lambda (&rest junk)
                   (abbrev-table-menu python-mode-abbrev-table)))
        "-"
        ["Start interpreter" python-shell
         :help "Run `inferior' Python in separate buffer"]
        ["Import/reload file" python-load-file
         :help "Load into inferior Python session"]
        ["Eval buffer" python-send-buffer
         :help "Evaluate buffer en bloc in inferior Python session"]
        ["Eval region" python-send-region :active mark-active
         :help "Evaluate region en bloc in inferior Python session"]
        ["Eval def/class" python-send-defun
         :help "Evaluate current definition in inferior Python session"]
        ["Switch to interpreter" python-switch-to-python
         :help "Switch to inferior Python buffer"]
        ["Set default process" python-set-proc
         :help "Make buffer's inferior process the default"
         :active (buffer-live-p python-buffer)]
        ["Check file" python-check :help "Run pychecker"]
        ["Debugger" pdb :help "Run pdb under GUD"]
        "-"
        ["Help on symbol" python-describe-symbol
         :help "Use pydoc on symbol at point"]
        ["Complete symbol" symbol-complete
         :help "Complete (qualified) symbol before point"]
        ["Find function" python-find-function
         :help "Try to find source definition of function at point"]
        ["Update imports" python-find-imports
         :help "Update list of top-level imports for completion"]))
    map))

Altri suggerimenti

Se si desidera Ctrl + C per agire come left e F12 per agire come C-c:

(define-key key-translation-map [f12] "\C-c")
(define-key key-translation-map "\C-c" [left])

Si noti che questo influenzerà anche binding multi-chiave, per esempio è ora necessario digitare Ctrl + X F12 per uscire Emacs. Il rovescio della medaglia è che C-c C-c è tipizzata come F12 F12 .

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top