Skip to content

Instantly share code, notes, and snippets.

@sheijk
Created January 26, 2021 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheijk/69fabc27a36ec00cb59aaeb8fc9643a7 to your computer and use it in GitHub Desktop.
Save sheijk/69fabc27a36ec00cb59aaeb8fc9643a7 to your computer and use it in GitHub Desktop.
A simple menu to move point to places on screen
;; Warning, code ripped from config, might not work as is
(require 'transient)
(require 'windmove)
(require 'window-numbering)
(require 'avy)
(defun shk-has-window-numbered (i)
"Return whether there is a window numbered `i' by window-numbering.el"
(let ((windows (car (gethash (selected-frame) window-numbering-table))))
(and (>= i 0) (< i 10)
(aref windows i))))
(shk-try-require-lazy 'link-hint)
(transient-define-prefix shk-jump-menu ()
"Menu to dispatch avy commands to move point to somewhere on screen."
[["Jump"
("o" "to word" avy-goto-word-1)
("s" "isearch" avy-goto-char-timer)
("L" "to line" avy-goto-line)
("w" "to word (no char query)" avy-goto-word-0)
("b" "open link" link-hint-open-link)
("B" "copy link" link-hint-copy-link)]
["By indentation"
("C-n" "next" (lambda () (interactive) (shk-change-line-same-indent (current-column) t)))
("C-p" "prev" (lambda () (interactive) (shk-change-line-same-indent (current-column) nil)))
("C-u" "up"
(lambda ()
(interactive)
(shk-change-line-same-indent
(save-excursion
(back-to-indentation)
(- (current-column) 1))
nil)))]])
(transient-insert-suffix 'shk-jump-menu (list 0 -1)
`["To window"
,@(loop for i from 0 to 9 collect
`(,(format "%s" i)
(lambda ()
(let ((win (shk-has-window-numbered ,i)))
(if win
(let ((name (buffer-name (window-buffer win))))
(if (> (length name) 20)
(format "%s…" (substring name 0 19))
name))
"(inactive)")))
,(symbol-append 'select-window- (format "%s" i))
:if
(lambda () (shk-has-window-numbered ,i))))])
(transient-define-prefix shk-move-window-menu ()
"A small menu to move windows around"
["Move to"
("i" "swap" windmove-swap-states-up)
("k" "down" windmove-swap-states-down)
("j" "left" windmove-swap-states-left)
("l" "right" windmove-swap-states-right)])
(transient-define-prefix shk-buffer-placement-menu ()
"A small menu to decide where the next buffer will be displayed"
["Move to"
("i" "up" windmove-display-up)
("k" "down" windmove-display-down)
("j" "left" windmove-display-left)
("l" "right" windmove-display-right)
("t" "new tab" windmove-display-new-tab)
("0" "same window" windmove-display-same-window)])
(transient-insert-suffix 'shk-jump-menu (list 0 -1)
`["Window"
("i" "up" windmove-up)
("k" "down" windmove-down)
("j" "left" windmove-left)
("l" "right" windmove-right)
("m" "move" shk-move-window-menu)
("n" "next" shk-buffer-placement-menu)])
(define-key global-map (kbd "C-o") 'shk-jump-menu)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment