about summary refs log tree commit diff stats
path: root/lisp/+mwim.el
blob: 97a2b040944f79b9ea666f442109a2c845696ed4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
;;; +mwim.el --- Extras -*- lexical-binding: t; -*-

;;; Commentary:

;;; Code:

(require 'seq)

(defgroup +mwim nil
  "Extra `mwim' customizations."
  :group 'mwim)

(defcustom +mwim-passthrough-modes nil
  "Modes to not move-where-I-mean."
  :type '(repeat function))

(defun +mwim-beginning-maybe (&optional arg)
  "Perform `mwim-beginning', maybe.
Will just do \\[beginning-of-line] in one of
`+mwim-passthrough-modes'."
  (interactive)
  (if (apply #'derived-mode-p +mwim-passthrough-modes)
      (let ((this-mode-map (symbol-value (intern (format "%s-map" major-mode))))
            (key "C-a"))
        (call-interactively (or (keymap-lookup this-mode-map key t t)
                     (keymap-lookup (current-global-map) key t t))))
    (call-interactively #'mwim-beginning)))

(defun +mwim-end-maybe (&optional arg)
  "Perform `mwim-beginning', maybe.
Will just do \\[end-of-line] in one of
`+mwim-passthrough-modes'."
  (interactive)
  (if (apply #'derived-mode-p +mwim-passthrough-modes)
      (let ((this-mode-map (symbol-value (intern (format "%s-map" major-mode))))
            (key "C-e"))
        (call-interactively (or (keymap-lookup this-mode-map key t t)
                                (keymap-lookup (current-global-map) key t t))))
    (call-interactively #'mwim-end)))

(provide '+mwim)
;;; +mwim.el ends here