2011-06-08 42 views
6

我想要一個小模式,它允許數字鍵上的移位符號以非移位方式訪問(然後移位數字)。看起來這可能對Perl代碼($,@,%等)有幫助。理想情況下,切換此模式會有一個關鍵。有點像大寫鎖,但只適用於數字鍵。Emacs中的未移位符號

這樣的模式已經存在嗎?

回答

9

一個推出自己的方法是這樣的:

(define-minor-mode snoopy-mode 
    "Toggle snoopy mode. 
    With no argument, this command toggles the mode. 
    Non-null prefix argument turns on the mode. 
    Null prefix argument turns off the mode." 
    ;; The initial value. 
    nil 
    ;; The indicator for the mode line. 
    " Snoopy" 
    ;; The minor mode bindings. 
    '(("1" . (lambda() (interactive) (insert-char ?! 1))) 
    ("!" . (lambda() (interactive) (insert-char ?1 1))) 
    ;;etc 
)) 

minor modeskeymaps

+0

太棒了!很棒! – dharmatech 2011-06-08 15:14:24

+0

那就是@&$ ^^#@!它的好名字! – dwarring 2011-06-10 04:59:39

+0

從這個答案中獲得靈感並創建了https://github.com/anmonteiro/snoopy-mode。它處理Paredit/Smartparens模式下打開和關閉括號的問題,答案沒有涵蓋。 – anmonteiro 2017-07-29 20:15:38

5

非常感謝jaybee的回答。下面是所有數的定義擴大:

(define-minor-mode shifted-numbers-mode 
    "Toggle shifted numbers mode." 
    nil 
    " shifted" 
    '(("1" . (lambda() (interactive) (insert-char ?! 1))) 
    ("2" . (lambda() (interactive) (insert-char [email protected] 1))) 
    ("3" . (lambda() (interactive) (insert-char ?# 1))) 
    ("4" . (lambda() (interactive) (insert-char ?$ 1))) 
    ("5" . (lambda() (interactive) (insert-char ?% 1))) 
    ("6" . (lambda() (interactive) (insert-char ?^ 1))) 
    ("7" . (lambda() (interactive) (insert-char ?& 1))) 
    ("8" . (lambda() (interactive) (insert-char ?* 1))) 
    ("9" . (lambda() (interactive) (insert-char ?(1))) 
    ("0" . (lambda() (interactive) (insert-char ?) 1))) 

    ("!" . (lambda() (interactive) (insert-char ?1 1))) 
    ("@" . (lambda() (interactive) (insert-char ?2 1))) 
    ("#" . (lambda() (interactive) (insert-char ?3 1))) 
    ("$" . (lambda() (interactive) (insert-char ?4 1))) 
    ("%" . (lambda() (interactive) (insert-char ?5 1))) 
    ("^" . (lambda() (interactive) (insert-char ?6 1))) 
    ("&" . (lambda() (interactive) (insert-char ?7 1))) 
    ("*" . (lambda() (interactive) (insert-char ?8 1))) 
    ("(" . (lambda() (interactive) (insert-char ?9 1))) 
    (")" . (lambda() (interactive) (insert-char ?0 1))))) 

在Perl中,括號往往更常見比括號所以您可能還需要:

("[" . (lambda() (interactive) (insert-char ?{ 1))) 
("]" . (lambda() (interactive) (insert-char ?} 1))) 

("{" . (lambda() (interactive) (insert-char ?[ 1))) 
("}" . (lambda() (interactive) (insert-char ?] 1))) 
1

這不是一個完整的解決方案,而是一個哥們的我寫了一個小模式,根據上下文自動插入短劃線或下劃線:Smart-Dash Mode

+0

這看起來不錯!謝謝! – dharmatech 2011-06-08 20:24:00