Emacs中未移位的符号

时间:2011-06-08 11:10:30

标签: perl emacs

我想要一种次要模式,它允许以不变的方式访问数字键上的移位符号(然后移动数字)。看来这可能对Perl代码($,@,%等等)有帮助。理想情况下,有一个切换此模式的键。类似于大写锁,但仅限于数字键。

这种模式是否已经存在?

3 个答案:

答案 0 :(得分: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

答案 1 :(得分: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 ?@ 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)))

答案 2 :(得分:1)

这不是一个完整的解决方案,但我的一个伙伴写了一个次要模式,根据上下文自动插入破折号或下划线:Smart-Dash Mode