Skip to content

Instantly share code, notes, and snippets.

# -*- mode: snippet; require-final-newline: nil -*-
# name: $
# key: $
# binding: direct-keybinding
# --
${1:${2:${3:foo }bar }baz }
${4:foo }${5:bar }${6:baz }
${7:foo ${8:bar ${9:baz }}}
# --
$${1:{${2:`(incf n)`}:${3:$(capitalize yas-text)}}}
(defun transient-map (keymap &optional pred onexit)
(defalias (-> ((user-error "It's an active map!")
(-contains? (current-active-maps))
(-compose 'symbol-value 'eq keymap)
(-andfn 'mapatoms 'boundp 'keymapp)
(-orfn (catch 'found) (cl-gens))))
(lambda (interactive "p") (keymap pred onexit)
(set-transient-map keymap pred onexit))))
(advice-add 'describe-prefix-bindings :after
(defun another-chance? (&rest args)
(unless (key-binding (this-command-keys))
(let ((path (listify-key-sequence (this-command-keys-vector))))
(set-transient-map (key-binding (vconcat (butlast path))))))))
(pp '(current-active-maps :aaaaaaaaaa
bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb adasd :aaaaaaaaaa bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb :AAAAAAAAAA BBBBBBBBBB))
qq
(current-active-maps :aaaaaaaaaa bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb adasd :aaaaaaaaaa bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb :AAAAAAAAAA BBBBBBBBBB)
"(current-active-maps :aaaaaaaaaa bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb adasd :aaaaaaaaaa bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb :aaaaaaaaaa bbbbbbbbbb :AAAAAAAAAA BBBBBBBBBB)
"
(setq-default scroll-up-aggressively 0.0)
(add-hook 'post-command-hook
(defun recenter+ ()
(unless (and (symbolp this-command) (get this-command 'scroll-command))
(with-current-buffer (window-buffer)
(recenter (- (1+ (save-excursion
(vertical-motion (floor (window-screen-lines) 2))))))))))
(define-key global-map [remap scroll-down-command]
(defun move-to-top-line () (interactive) (move-to-window-line 1)))
(define-key global-map [remap scroll-up-command]
(cl-defun transient-map (command &rest bindings &key keep-pred
on-exit &allow-other-keys)
(unless (commandp command) (push command bindings)
(setq command nil))
(let* ((keymap (-map (-applify 'cons) (-partition 2 bindings))))
(set-transient-map (easy-mmode-define-keymap keymap) keep-pred on-exit))
(when command (call-interactively command)))
(cl-defun test (&key bar)
(message "bar: %s" bar))
(test :bar 'qwe)
;; "bar: qwe"
(cl-defun test (&rest foo &key bar)
(message "foo: %s bar: %s" foo bar))
(test 'qwe :bar 'asd)
;; (error "Keyword argument qwe not one of (:bar)")