summaryrefslogtreecommitdiff
path: root/embark-conf.el
blob: d03b5bc1bd2be478088a89c40e0d685a6cea3c1a (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
(use-package "embark" 'embark
  (define-key global-map (vector ?\s-,) #'embark-act)
  (define-key global-map (vector ?\s-.) #'embark-act-noexit)

  (define-key minibuffer-local-completion-map (vector ?\M-q) #'embark-collect-toggle-view)
  (define-key minibuffer-local-completion-map (vector ?\s-:) #'embark-collect-live)
  (define-key minibuffer-local-completion-map (vector 'down) #'durand-embark-scroll-down-or-go-to-completions)
  (define-key minibuffer-local-completion-map (vector 'up) #'durand-embark-scroll-up-or-go-to-completions)
  (define-key minibuffer-local-completion-map (vector ?\M-o) #'embark-export)
  (define-key minibuffer-local-completion-map (vector ?\C-o) #'embark-export)
  (define-key minibuffer-local-completion-map (vector ?\M-v) #'embark-switch-to-collect-completions)
  (define-key embark-collect-mode-map (vector ?,) #'embark-act)
  (define-key embark-collect-mode-map (vector ?\M-o) #'embark-export)
  (define-key embark-collect-mode-map (vector ?\C-o) #'embark-export)
  (define-key embark-collect-mode-map (vector ?\M-t) #'toggle-truncate-lines)
  (define-key embark-collect-mode-map (vector ?\M-q) #'embark-collect-toggle-view)
  (define-key embark-collect-mode-map (vector 'down) #'durand-completion-scroll-down-or-go-to-minibuffer)
  (define-key embark-collect-mode-map (vector 'up) #'durand-completion-scroll-up-or-go-to-minibuffer)

  (define-key completion-list-mode-map (vector 'down) #'durand-completion-scroll-down-or-go-to-minibuffer)
  (define-key completion-list-mode-map (vector 'up) #'durand-completion-scroll-up-or-go-to-minibuffer)

  ;; (define-key embark-file-map (vector ?v) #'view-file)

  (define-key embark-general-map (vector ?v) (lambda (&rest _args)
                                               (interactive)
                                               (cond
                                                ((buffer-file-name)
                                                 (view-file (buffer-file-name))))))
  (define-key embark-general-map (vector 127) #'durand-switch-other-buffer)

;;;###autoload
  (defun durand-switch-other-buffer (&rest _args)
    "switch to the last used buffer"
    (interactive)
    (switch-to-buffer (other-buffer)))

;;;###autoload
  (defun prot-embark--live-collect-fit-window (&rest _)
    "Fit Embark's live collect window to its buffer.
To be added to `embark-collect-post-revert-hook'."
    (when (string-match-p "Live" (buffer-name))
      (fit-window-to-buffer (get-buffer-window)
                            (floor (frame-height) 2) 1)))
  
;;;###autoload
  (defun prot-embark--live-buffer-p ()
    "Determine presence of a linked live collect buffer."
    (let* ((buf-link embark-collect-linked-buffer)
           (buf-name (buffer-name buf-link)))
      (when buf-name
        (string-match-p "Embark Live Collect" buf-name))))

;;;###autoload
  (defun prot-embark-live-collect-toggle ()
    "Toggle `embark-live-collect', call `prot-embark-live-collect-hook'."
    (interactive)
    (if (prot-embark--live-buffer-p)
        (kill-buffer embark-collect-linked-buffer)
      (embark-collect-live)))

;;;###autoload
  (defun durand-embark-scroll-down-or-go-to-completions (&optional arg)
    "Scroll down; if this is not feasible, go to the completions buffer.
ARG means do this command ARG times."
    (interactive "p")
    (let ((original-point (point))
          (left (abs (forward-line arg)))
          (completion-windows
           (delq nil
                 (mapcar
                  (lambda (w)
                    (and (consp
                          (delq nil
                                (mapcar (lambda (name)
                                          (string-match-p
                                           name
                                           (buffer-name (window-buffer w))))
                                        durand-completion-buffer-names)))
                         w))
                  (window-list nil 'nomini))))
          (in-completion-p (consp
                           (delq nil
                                 (mapcar
                                  (lambda (name)
                                    (string-match-p name (buffer-name)))
                                  durand-completion-buffer-names)))))
      (cond ((= (point) (point-max))
             (setq left (1+ left)))
            ((get-text-property (point) 'field)
             (goto-char original-point)))
      (cond ((and (> left 0)
                  (consp completion-windows)
                  (not in-completion-p))
             (select-window (car completion-windows))
             (cond
              ((> arg 0)
               (goto-char (point-min))
               (cond
                ((derived-mode-p 'completion-list-mode)
                 (next-completion 1))))
              ((< arg 0)
               (goto-char (point-max))
               (cond
                ((derived-mode-p 'completion-list-mode)
                 (next-completion -1)))))))))

;;;###autoload
  (defun durand-embark-scroll-up-or-go-to-completions (&optional arg)
    "Scroll up; if this is not feasible, go to the completions buffer.
ARG means do this command ARG times."
    (interactive "p")
    (durand-embark-scroll-down-or-go-to-completions (- arg)))

;;;###autoload
  (defun durand-completion-scroll-down-or-go-to-minibuffer (&optional arg)
    "Scroll down; if this is not feasible, go to the mini-buffer.
ARG means do this command ARG times."
    (interactive "p")
    (let ((original-point (point))
          (left (abs (forward-line arg)))
          (minibuffer-active-p (active-minibuffer-window))
          (in-minibuffer-p (minibuffer-window-active-p (selected-window))))
      (cond ((= (point) (point-max))
             (setq left (1+ left)))
            ((get-text-property (point) 'field)
             (goto-char original-point)))
      (cond ((and (> left 0)
                  minibuffer-active-p
                  (not in-minibuffer-p))
             (select-window (active-minibuffer-window))
             (cond
              ((> arg 0)
               (goto-char (point-min)))
              ((< arg 0)
               (goto-char (point-max))))))))

;;;###autoload
  (defun durand-completion-scroll-up-or-go-to-minibuffer (&optional arg)
    "Scroll up; if this is not feasible, go to the mini-buffer.
ARG means do this command ARG times."
    (interactive "p")
    (durand-completion-scroll-down-or-go-to-minibuffer (- arg)))

  ;; (set 'embark-occur-minibuffer-completion t)

  (add-hook 'embark-collect-post-revert-hook #'prot-embark--live-collect-fit-window))

;;; Actually there is no difference between putting the configuration
;;; after and inside the use-package form.

(define-key input-decode-map (vector 27) nil)
(define-key input-decode-map (vector 27) (vector 'escape))

(define-key global-map (vector 'escape) #'embark-act)

(use-package "marginalia" 'marginalia
  (setq marginalia-annotators
        '(marginalia-annotators-heavy
          marginalia-annotators-light))
  (marginalia-mode 1))