Reputation: 9527
I'd like a minor mode which allows the shifted symbols on the number keys to be accessible in an unshifted fashion (and the digits to then be shifted). It seems this might be helpful with Perl code ($, @, %, etc...). Ideally, there'd be a key for toggling this mode. Sort of like capslock but only for the number keys.
Does such a mode already exist?
Upvotes: 6
Views: 748
Reputation: 1925
One way to roll your own would be something like this:
(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
))
See minor modes and keymaps.
Upvotes: 9
Reputation: 9527
Thanks very much to jaybee for the answer. Here's an expanded definition for all the numbers:
(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)))))
In Perl, braces are often more common than brackets so you might also want:
("[" . (lambda () (interactive) (insert-char ?{ 1)))
("]" . (lambda () (interactive) (insert-char ?} 1)))
("{" . (lambda () (interactive) (insert-char ?[ 1)))
("}" . (lambda () (interactive) (insert-char ?] 1)))
Upvotes: 5
Reputation: 2830
This isn't a complete solution, but a buddy of mine wrote a minor mode that inserts dash or underscore automatically depending on the context: Smart-Dash Mode
Upvotes: 1