summaryrefslogtreecommitdiff
path: root/common.el
blob: dd125391295407749d21733b053653f7459efa5f (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
;;; common.el --- Some common functions -*- lexical-binding: t; -*-

;;;###autoload
(defun center-string-in-width (str width)
  "Add spaces to STR so that it is centered in a box which is WIDTH wide."
  (let ((len (length str)))
    (cond
     ((> len width)
      (error "String %s longer than %d" str width))
     (t (format "%s%s"
                (make-string (round (- width len) 2)
                             32)
                str)))))

;;; jump between the completions buffer and the minibuffer

;;;###autoload
(defvar durand-completion-buffer-names (list "Completions"
                                             "Embark Live Occur"
                                             "comb")
  "The list of names that match the names of \"completion buffers\".")

;;;###autoload
(defun durand-focus-completion-or-minibuffer (&optional arg)
  "Jump between the completions buffer and the minibuffer."
  (interactive "P")
  (let* ((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))))
         (minibuffer-active-p (active-minibuffer-window))
         (in-minibuffer-p (minibuffer-window-active-p (selected-window))))
    (cond
     ((and minibuffer-active-p
           (not in-minibuffer-p))
      (select-window (active-minibuffer-window)))
     ((and (consp completion-windows)
           (not in-completion-p))
      (select-window (car completion-windows)))
     (t
      (other-window 1)))))

;;; Intentionally disable some key-bindings.

;;;###autoload
(defun intentionally-disabled-bind ()
  "Warn the user that this key-binding is intentionally disabled."
  (interactive)
  (user-error "You pressed an intentionally disabled key-binding: %s"
              (key-description (this-command-keys-vector))))



(provide 'common)
;;; common.el ends here.