From dc206ebe9397d656971ba7fc3a092009ef4e797a Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sat, 9 Jan 2021 14:22:00 +0800 Subject: temporary state --- common.el | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 common.el (limited to 'common.el') 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. + + + -- cgit v1.2.3-18-g5258