1 ;;; bandali-utils.el --- useful utilities -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2020 Amin Bandali
5 ;; Author: Amin Bandali <bandali@gnu.org>
6 ;; Keywords: lisp, tools
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
23 ;; A small collection of useful utilities used through my init files.
27 (defmacro b
/setq-every
(value &rest vars
)
28 "Set all the variables from VARS to value VALUE."
29 (declare (indent defun
) (debug t
))
30 `(progn ,@(mapcar (lambda (x) (list 'setq x value
)) vars
)))
32 (defun b/start-process
(program &rest args
)
33 "Same as `start-process', but doesn't bother about name and buffer."
34 (let ((process-name (concat program
"_process"))
35 (buffer-name (generate-new-buffer-name
36 (concat program
"_output"))))
37 (apply #'start-process
38 process-name buffer-name program args
)))
40 (defun b/dired-start-process
(program &optional args
)
41 "Open current file with a PROGRAM."
42 ;; Shell command looks like this: "program [ARGS]... FILE" (ARGS can
43 ;; be nil, so remove it).
44 (declare-function dired-get-file-for-visit
"dired")
45 (apply #'b
/start-process
47 (remove nil
(list args
(dired-get-file-for-visit)))))
49 (defun b/add-elisp-section
()
53 (insert "\n\f\n;;; "))
55 ;; (defvar b/fill-column 47
56 ;; "My custom `fill-column'.")
58 (defconst b
/asterism
"* * *")
60 (defun b/insert-asterism
()
61 "Insert a centred asterism."
66 (make-string (floor (/ (- fill-column
(length b
/asterism
)) 2))
71 (defun b/no-mouse-autoselect-window
()
72 "Conveniently disable `focus-follows-mouse'.
73 For disabling the behaviour for certain buffers and/or modes."
74 (make-local-variable 'mouse-autoselect-window
)
75 (setq mouse-autoselect-window nil
))
77 (defun b/kill-current-buffer
()
78 "Kill the current buffer."
79 ;; also see https://redd.it/64xb3q
81 (kill-buffer (current-buffer)))
83 (defun b/move-indentation-or-beginning-of-line
(arg)
84 "Move to the indentation or to the beginning of line."
87 ;; (back-to-indentation)
88 ;; (move-beginning-of-line arg))
90 (progn (back-to-indentation)
92 (move-beginning-of-line arg
)))
94 (defun b/join-line-top
()
95 "Like `join-line', but join next line to the current line."
99 (defun b/duplicate-line-or-region
(&optional n
)
100 "Duplicate the current line, or region (if active).
101 Make N (default: 1) copies of the current line or region."
103 (let ((u-r-p (use-region-p)) ; if region is active
108 (buffer-substring (region-beginning) (region-end))
109 (prog1 (thing-at-point 'line
)
113 (forward-line 1))))))
114 (dotimes (_ (abs n1
))
117 (provide 'bandali-utils
)
118 ;;; bandali-utils.el ends here