summaryrefslogtreecommitdiff
path: root/common.el
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-01-09 14:22:00 +0800
committerJSDurand <mmemmew@gmail.com>2021-01-09 14:22:00 +0800
commitdc206ebe9397d656971ba7fc3a092009ef4e797a (patch)
treed963873011122fdf0eafeba89afd487115994bc5 /common.el
parenta2f7f2bf9077ba8acfc550575b9e21aa9ffe7bae (diff)
temporary state
Diffstat (limited to 'common.el')
-rw-r--r--common.el73
1 files changed, 73 insertions, 0 deletions
diff --git a/common.el b/common.el
new file mode 100644
index 0000000..dd12539
--- /dev/null
+++ b/common.el
@@ -0,0 +1,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.
+
+
+