Fold lisp/bandali-utils.el back into init.el
[~bandali/configs] / init.el
diff --git a/init.el b/init.el
index 870f265..958f457 100644 (file)
--- a/init.el
+++ b/init.el
@@ -78,7 +78,7 @@
                     exwm-workspace-current-index))))))))
 
   ;; make some mode-line spaces smaller
-  (csetq
+  (setq-default
    mode-line-format
    (mapcar
     (lambda (x)
       user-mail-address "bandali@gnu.org")
 
 \f
-;;; Package management
+;;; csetq (`custom' setq)
+
+(require 'cl-lib)
+
+(defmacro csetq (&rest args)
+  "Set the value of user option VAR to VALUE.
 
-;; (progn ;   `borg'
-;;   (add-to-list 'load-path
-;;                (expand-file-name "lib/borg" user-emacs-directory))
-;;   (require 'borg)
-;;   (borg-initialize)
-;;   (setq borg-rewrite-urls-alist
-;;         '(("git@github.com:" . "https://github.com/")
-;;           ("git@gitlab.com:" . "https://gitlab.com/"))))
+More generally, you can use multiple variables and values, as in
+  (csetq VAR VALUE VAR VALUE...)
+This sets each user option VAR's value to the corresponding VALUE.
+
+\(fn [VAR VALUE]...)"
+  (declare (debug setq))
+  `(progn
+     ,@(cl-loop for (var value) on args by 'cddr
+                collect
+                `(funcall (or (get ',var 'custom-set) #'set-default)
+                          ',var ,value))))
+
+\f
+;;; Package management
 
 ;; variables of interest:
 ;;   package-archive-priorities
     (csetq
      package-archives
      `(,@package-archives
-       ("org" . "https://orgmode.org/elpa/")
-       ("bndl" . "https://p.bndl.org/elpa/"))))
+       ;; ("bndl" . "https://p.bndl.org/elpa/")
+       ("org" . "https://orgmode.org/elpa/"))
+     package-load-list
+     '(;; GNU ELPA
+       (ivy "0.13.1")
+       (counsel "0.13.1")
+       (swiper "0.13.1")
+       (debbugs "0.26")
+       (delight "1.7")
+       (ebdb "0.6.19")
+       (orgalist "1.13")
+       (rt-liberation "1.31")
+       (yasnippet "0.14.0")
+       ;; bndl
+       (refinery-theme "0.1.1")
+       ;; Org ELPA
+       (org-plus-contrib "20201005"))))
   (package-initialize))
 
 (csetq package-archive-upload-base "/ssh:caffeine:~/www/p/elpa")
   ;; while at it, treat themes as safe
   ;; (setf custom-safe-themes t)
   ;; only one custom theme at a time
-  (comment
-    (defadvice load-theme (before clear-previous-themes activate)
-      "Clear existing theme settings instead of layering them"
-      (mapc #'disable-theme custom-enabled-themes))))
+  ;; (defadvice load-theme (before clear-previous-themes activate)
+  ;;   "Clear existing theme settings instead of layering them"
+  ;;   (mapc #'disable-theme custom-enabled-themes))
+  )
 
 ;; load the secrets file if it exists, otherwise show a warning
-(comment
-  (with-demoted-errors
-      (load (b/etc "secrets"))))
+;; (with-demoted-errors
+;;     (load (b/etc "secrets")))
 
 ;; start up emacs server.  see
 ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html#Emacs-Server
 (set-fontset-font t 'arabic "Vazir")
 
 ;; unicode support
-(comment
-  (dolist (ft (fontset-list))
-    (set-fontset-font
-     ft
-     'unicode
-     (font-spec :name "Source Code Pro" :size 14))
-    (set-fontset-font
-     ft
-     'unicode
-     (font-spec :name "DejaVu Sans Mono")
-     nil
-     'append)
-    ;; (set-fontset-font
-    ;;  ft
-    ;;  'unicode
-    ;;  (font-spec
-    ;;   :name "Symbola monospacified for DejaVu Sans Mono")
-    ;;  nil
-    ;;  'append)
-    ;; (set-fontset-font
-    ;;  ft
-    ;;  #x2115  ; ℕ
-    ;;  (font-spec :name "DejaVu Sans Mono")
-    ;;  nil
-    ;;  'append)
-    (set-fontset-font
-     ft
-     (cons ?Α ?ω)
-     (font-spec :name "DejaVu Sans Mono" :size 14)
-     nil
-     'prepend)))
+;; (dolist (ft (fontset-list))
+;;   (set-fontset-font
+;;    ft
+;;    'unicode
+;;    (font-spec :name "Source Code Pro" :size 14))
+;;   (set-fontset-font
+;;    ft
+;;    'unicode
+;;    (font-spec :name "DejaVu Sans Mono")
+;;    nil
+;;    'append)
+;;   ;; (set-fontset-font
+;;   ;;  ft
+;;   ;;  'unicode
+;;   ;;  (font-spec
+;;   ;;   :name "Symbola monospacified for DejaVu Sans Mono")
+;;   ;;  nil
+;;   ;;  'append)
+;;   ;; (set-fontset-font
+;;   ;;  ft
+;;   ;;  #x2115  ; ℕ
+;;   ;;  (font-spec :name "DejaVu Sans Mono")
+;;   ;;  nil
+;;   ;;  'append)
+;;   (set-fontset-font
+;;    ft
+;;    (cons ?Α ?ω)
+;;    (font-spec :name "DejaVu Sans Mono" :size 14)
+;;    nil
+;;    'prepend))
 
 ;;;; Elisp-level customizations
 
 (global-set-key (kbd "C-x v C-=") #'vc-ediff)
 
 (with-eval-after-load 'vc-git
-  (csetq vc-git-print-log-follow t))
+  (csetq vc-git-print-log-follow t
+         vc-git-show-stash 0))
 
 (csetq ediff-window-setup-function 'ediff-setup-windows-plain
        ediff-split-window-function 'split-window-horizontally)
  authinfo-hidden (regexp-opt '("password" "client-secret" "token")))
 
 \f
+;;; Useful utilities
+
+(defun b/add-elisp-section ()
+  (interactive)
+  (insert "\n")
+  (forward-line -1)
+  (insert "\n\f\n;;; "))
+
+(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/start-process (program &rest args)
+  "Same as `start-process', but doesn't bother about name and buffer."
+  (let ((process-name (concat program "_process"))
+        (buffer-name  (generate-new-buffer-name
+                       (concat program "_output"))))
+    (apply #'start-process
+           process-name buffer-name program args)))
+
+(defun b/no-mouse-autoselect-window ()
+  "Conveniently disable `focus-follows-mouse'.
+For disabling the behaviour for certain buffers and/or modes."
+  (make-local-variable 'mouse-autoselect-window)
+  (setq mouse-autoselect-window nil))
+
+(defun b/kill-current-buffer ()
+  "Kill the current buffer."
+  ;; also see https://redd.it/64xb3q
+  (interactive)
+  (kill-buffer (current-buffer)))
+
+(defun b/move-indentation-or-beginning-of-line (arg)
+  "Move to the indentation or to the beginning of line."
+  (interactive "^p")
+  ;; (if (bolp)
+  ;;     (back-to-indentation)
+  ;;   (move-beginning-of-line arg))
+  (if (= (point)
+         (progn (back-to-indentation)
+                (point)))
+      (move-beginning-of-line arg)))
+
+(defun b/join-line-top ()
+  "Like `join-line', but join next line to the current line."
+  (interactive)
+  (join-line 1))
+
+(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))))))
+
+\f
 ;;; General key bindings
 
 (global-set-key (kbd "C-a") #'b/move-indentation-or-beginning-of-line)
 \f
 ;;; Essential packages
 
+(add-to-list
+ 'load-path
+ (expand-file-name
+  (convert-standard-filename "lisp") user-emacs-directory))
+
 ;; (require 'bandali-exwm)
 
 (require 'bandali-org)
 
 (require 'bandali-theme)
 
-;; magit, *the* right way to do git
-(comment
-(csetq transient-history-file (b/var "transient/history.el")
-       transient-levels-file  (b/etc "transient/levels.el")
-       transient-values-file  (b/etc "transient/values.el"))
-(with-eval-after-load 'magit
-  (declare-function magit-add-section-hook "magit-section"
-                    (hook function &optional at append local))
-  (magit-add-section-hook 'magit-status-sections-hook
-                          'magit-insert-modules
-                          'magit-insert-stashes
-                          'append)
-  ;; (magit-add-section-hook 'magit-status-sections-hook
-  ;;                         'magit-insert-ignored-files
-  ;;                         'magit-insert-untracked-files
-  ;;                         'append)
-  (declare-function magit-display-buffer-fullframe-status-v1
-                    "magit-mode" (buffer))
-  (csetq
-   magit-diff-refine-hunk t
-   magit-repository-directories '(("~/.emacs.d/" . 0)
-                                  ("~/src/git/" . 2))
-   ;; magit-completing-read-function 'magit-ido-completing-read
-   magit-display-buffer-function
-   #'magit-display-buffer-fullframe-status-v1)
-  (nconc magit-section-initial-visibility-alist
-         '(([unpulled status] . show)
-           ([unpushed status] . show)))
-  (custom-set-faces '(magit-diff-file-heading ((t (:weight normal)))))
-
-  (with-eval-after-load 'magit-extras
-    (csetq
-     magit-pop-revision-stack-format
-     (pcase-let ((`(,pt ,_eob ,index-regexp)
-                  (default-value 'magit-pop-revision-stack-format)))
-       `(,pt "[%N: %h]: %ci\n  %s
-  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=%H"
-             ,index-regexp)))))
-;; global key bindings
-(global-set-key (kbd "C-x g") #'magit-status)
-(global-set-key (kbd "C-c g b") #'magit-blame-addition)
-(global-set-key (kbd "C-c g l") #'magit-log-buffer-file)
-(global-set-key (kbd "C-c g y") #'magit-pop-revision-stack)
-)
+;; (require 'bandali-magit)
 
 ;; recently opened files
 (csetq recentf-max-saved-items 2000
 ;; IRC (with ERC)
 (require 'bandali-erc)
 
+;; 'paste' service (aka scp + web server)
 (add-to-list 'load-path (b/lisp "scpaste"))
 (with-eval-after-load 'scpaste
   (csetq scpaste-http-destination "https://p.bndl.org"