summaryrefslogtreecommitdiffstats
path: root/.emacs.d/lisp/bandali-utils.el
diff options
context:
space:
mode:
authorAmin Bandali <bandali@kelar.org>2025-02-08 10:38:38 -0500
committerAmin Bandali <bandali@kelar.org>2025-02-08 10:38:38 -0500
commit7b718d276e1d9f01287baea7187baef618e6b947 (patch)
treed641aae211c780b78b7a8d3111ed6aa70b36649e /.emacs.d/lisp/bandali-utils.el
parentf0ad1b1cbe334c004012205fdb9af81bb7c3a538 (diff)
downloadconfigs-7b718d276e1d9f01287baea7187baef618e6b947.tar.gz
configs-7b718d276e1d9f01287baea7187baef618e6b947.tar.xz
configs-7b718d276e1d9f01287baea7187baef618e6b947.zip
Add bandali-essentials and bandali-utils, use use-package
Diffstat (limited to '')
-rw-r--r--.emacs.d/lisp/bandali-utils.el94
1 files changed, 94 insertions, 0 deletions
diff --git a/.emacs.d/lisp/bandali-utils.el b/.emacs.d/lisp/bandali-utils.el
new file mode 100644
index 0000000..9edc91e
--- /dev/null
+++ b/.emacs.d/lisp/bandali-utils.el
@@ -0,0 +1,94 @@
+;;; bandali-utils.el --- useful utilities -*- lexical-binding: t; -*-
+
+;; Copyright (c) 2018-2025 Amin Bandali <bandali@gnu.org>
+
+;; Author: Amin Bandali <bandali@gnu.org>
+;; Keywords: convenience
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Some useful utilities.
+
+;;; Code:
+
+(defun b/insert-asterism ()
+ "Insert a centred asterism."
+ (interactive)
+ (let ((asterism "* * *"))
+ (insert
+ (concat
+ "\n"
+ (make-string
+ (floor (/ (- fill-column (length asterism)) 2))
+ ?\s)
+ asterism
+ "\n"))))
+
+(defun b/join-line-top ()
+ "Like `join-line', but join next line to the current line."
+ (interactive)
+ (join-line 1))
+
+(defun b/*scratch* ()
+ "Switch to `*scratch*' buffer, creating it if it does not exist."
+ (interactive)
+ (let ((fun (if (functionp #'get-scratch-buffer-create)
+ #'get-scratch-buffer-create ; (version<= "29" emacs-version)
+ #'startup--get-buffer-create-scratch))) ; (version< emacs-version "29")
+ (switch-to-buffer (funcall fun))))
+
+(defun b/duplicate-line-or-region (&optional n)
+ "Duplicate the current line, or region (if active).
+Make N (default: 1) copies of the current line or region."
+ (interactive "*p")
+ (let ((u-r-p (use-region-p)) ; if region is active
+ (n1 (or n 1)))
+ (save-excursion
+ (let ((text
+ (if u-r-p
+ (buffer-substring (region-beginning) (region-end))
+ (prog1 (thing-at-point 'line)
+ (end-of-line)
+ (if (eobp)
+ (newline)
+ (forward-line 1))))))
+ (dotimes (_ (abs n1))
+ (insert text))))))
+
+(defun b/invert-default-face (arg)
+ "Invert the `default' and `mode-line' faces for the current frame.
+Swap the background and foreground for the two `default' and
+`mode-line' faces, effectively acting like a simple light/dark
+theme toggle. If prefix argument ARG is given, invert the faces
+for all frames."
+ (interactive "P")
+ (let ((frame (unless arg
+ (selected-frame))))
+ (invert-face 'default frame)
+ (invert-face 'mode-line frame)
+ (when (fboundp #'exwm-systemtray--refresh-background-color)
+ (exwm-systemtray--refresh-background-color 'remap))))
+
+(defun b/unfill-paragraph-or-region (&optional beg end)
+ "Unfill paragraph, or region (if active)."
+ (interactive "r")
+ (let ((fill-column most-positive-fixnum))
+ (if (use-region-p)
+ (fill-region beg end)
+ (fill-paragraph))))
+
+(provide 'bandali-utils)
+;;; bandali-utils.el ends here