;;; 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 Collect" "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)))) ;;; Hide some minor mode from the mode line display. ;;;###autoload (defmacro durand-hide-minor-mode (minor) "Hide MINOR from the mode line." `(setcdr (assq ',minor minor-mode-alist) (list ""))) (provide 'common) ;;; common.el ends here.