Emacs Experimental Hyper-Key Mappings

In a previous post Remapping My Caps Lock Key I mentioned that I remapped my caps-lock key to escape, but also created a “hyper-key” (ctrl-shift-cmd-opt) when the caps-lock key is held down. This opens up a keyboard worth of new shortcuts for emacs. Here are a few I have been playing with for the past few days. An alternative key mapping would be to map the hyper key to holding down the tab key, if you already have the caps lock key mapped to control, and thus muscle memory might preclude this mapping from working for you.

H is the remapped caps-lock HyperKey from my earlier post, which translates as C-M-S-s in the emacs init.el key-mappings. I include an init.el excerpt at the end of the post for all of these mappings.

  • (H-l) This will mark the entire current line, from any position on the line. Using the arrow keys will extent the selection one line at a time either up or down.
  • (H-f) This invokes text expansion for code completion, I do this a lot so I wanted it to be very comfortable.
  • (H-3) This invokes the comment/uncomment function on a region, ruby comment is the # so I thought I would try this binding.
  • (H-Right Arrow) This opens a new window to the right of the current window, I do this often enough I wanted it to be quick
  • (H-Left Arrow) This closes the current window, sort of the opposite of Right arrow.
  • (H-Down Arrow) This opens a new window below the current window
  • (H-p) In the current window switch to the previous buffer
  • (H-n) In the current window switch to the next buffer
  • (H-delete) Kill this buffer
  • (H-w) Quick copy line, pressing multiple times adds more lines to the copy
  • (H-k) Quick cut line, pressing multiple times adds more lines to the cut
  • (H-c) Copy region into register (prompts for register number)
  • (H-v) Paste from register (prompts for register number)
  • (H-spacebar) Open a popup shell in directory of current buffer.
  • (H-e) Eval buffer, mostly used to eval init.el after tweaks

I will likely be tweaking more in the upcoming weeks as I experiment with key mappings, I will post an update after I get a chance to work with the hyper-key for a while, and settle on a favorite set of key-mappings. See the excerpt from my init.el below.

gistfile1.txtlink
(defun quick-copy-line ()
"Copy the whole line that point is on and move to the beginning of the next line.
Consecutive calls to this command append each line to the
kill-ring."
(interactive)
(let ((beg (line-beginning-position 1))
(end (line-beginning-position 2)))
(if (eq last-command 'quick-copy-line)
(kill-append (buffer-substring beg end) (< end beg))
(kill-new (buffer-substring beg end))))
(beginning-of-line 2))
(defun quick-cut-line ()
"Cut the whole line that point is on. Consecutive calls to this command append each line to the kill-ring."
(interactive)
(let ((beg (line-beginning-position 1))
(end (line-beginning-position 2)))
(if (eq last-command 'quick-cut-line)
(kill-append (buffer-substring beg end) (< end beg))
(kill-new (buffer-substring beg end)))
(delete-region beg end))
(beginning-of-line 1)
(setq this-command 'quick-cut-line))
(transient-mark-mode 1)
(defun select-current-line ()
"Select the current line"
(interactive)
(end-of-line) ; move to end of line
(set-mark (line-beginning-position)))
(define-key help-map "d" 'docsetutil-search) ; C-h d
(defvar th-shell-popup-buffer nil)
(defun th-shell-popup ()
"Toggle a shell popup buffer with the current file's directory as cwd."
(interactive)
(unless (buffer-live-p th-shell-popup-buffer)
(save-window-excursion (shell "*Popup Shell*"))
(setq th-shell-popup-buffer (get-buffer "*Popup Shell*")))
(let ((win (get-buffer-window th-shell-popup-buffer))
(dir (file-name-directory (or (buffer-file-name)
;; dired
dired-directory
;; use HOME
"~/"))))
(if win
(quit-window nil win)
(pop-to-buffer th-shell-popup-buffer nil t)
(comint-send-string nil (concat "cd " dir "\n")))))
(global-set-key (kbd "C-M-S-s-l") 'select-current-line)
(global-set-key (kbd "C-M-S-s-f") 'hippie-expand)
(global-set-key (kbd "C-M-s-#") 'comment-or-uncomment-region)
(global-set-key (kbd "C-M-S-s-<left>") 'delete-window)
(global-set-key (kbd "C-M-S-s-<SPC>") 'th-shell-popup)
(global-set-key (kbd "C-M-S-s-p") 'switch-to-prev-buffer)
(global-set-key (kbd "C-M-S-s-n") 'switch-to-next-buffer)
(global-set-key (kbd "C-M-S-s-v") 'insert-register)
(global-set-key (kbd "C-M-S-s-c") 'copy-to-register)
(global-set-key (kbd "C-M-S-s-e") 'eval-buffer)
(global-set-key (kbd "C-M-S-s-<right>") 'split-window-right)
(global-set-key (kbd "C-M-S-s-<down>") 'split-window-below)
(global-set-key (kbd "C-M-S-s-<backspace>") 'kill-this-buffer)
(global-set-key (kbd "C-M-S-s-w") 'quick-copy-line)
(global-set-key (kbd "C-M-S-s-k") 'quick-cut-line)

Comments