Compare commits

...

12 Commits

Author SHA1 Message Date
Case Duckworth 5d4db143f2 Indentation 2022-05-01 09:36:27 -05:00
Case Duckworth 4e562b202c Add `+indent-rigidly'
This works line-wise if the region isn't active.
2022-05-01 09:36:07 -05:00
Case Duckworth 8360e66d11 Allow passing a list of modes to `+mapc-some-buffers'
Due to the way this is written, I can't pass one mode by itself---it must be a
list.
2022-05-01 09:26:59 -05:00
Case Duckworth a6341764f3 Add geiser-guile 2022-05-01 09:25:49 -05:00
Case Duckworth 9a8043d49b Configure eros 2022-05-01 09:25:36 -05:00
Case Duckworth 23836a13f1 Take advantage of `eww-auto-rename-buffer' if it exists 2022-05-01 09:25:25 -05:00
Case Duckworth 13fed66dec Add bindings for consult functions 2022-05-01 09:25:12 -05:00
Case Duckworth 2cc59cf768 Add +org-wrap-on-hyphens 2022-05-01 09:24:57 -05:00
Case Duckworth 02b8882f54 Indentation 2022-05-01 09:24:44 -05:00
Case Duckworth 0730f1e1ac Add +compile-dispatch
At some point I probably should add a +recompile .. or something, I'm not sure
how the compile flow works in Emacs.
2022-05-01 09:21:51 -05:00
Case Duckworth 5c02bbc592 Remove (:quit)-ed setup forms 2022-05-01 09:21:39 -05:00
Case Duckworth 818cfc0380 Return point to the same point relative of defun in +init-sort 2022-05-01 09:11:41 -05:00
5 changed files with 153 additions and 116 deletions

95
init.el
View File

@ -42,11 +42,12 @@
"C-w" #'+kill-word-backward-or-region
"C-x C-m" #'execute-extended-command ; original: coding systems
"C-<backspace>" #'+backward-kill-word
"C-x TAB" #'+indent-rigidly
;; Alright, Yegge... NOPE! C-x t is tab prefix ... (maybe F6 or something?)
;; "C-x t" #'beginning-of-buffer
;; "C-x e" #'end-of-buffer
)
;; ;; C-h deletes backward - see https://idiomdrottning.org/bad-emacs-defaults
;; C-h deletes backward - see https://idiomdrottning.org/bad-emacs-defaults
(global-set-key (kbd "C-h") 'delete-backward-char)
(keyboard-translate ?\C-h ?\C-?)
;; Faces
@ -70,7 +71,7 @@
(setup (:require +init)
(:local-hook user-save-hook #'+init-sort)
(+with-ensure-after-init
(:hook #'+init-add-setup-to-imenu)))
(:hook #'+init-add-setup-to-imenu)))
(setup (:require auth-source)
(:option auth-sources (list 'default
@ -85,7 +86,7 @@
(setup (:require autoinsert)
(setf (alist-get "\\.scm" auto-insert-alist nil nil #'equal)
'(insert "#!/bin/sh\n#| -*- scheme -*-\nexec csi -s $0 \"$@\"\n|#\n"))
;; (auto-insert-mode +1)
;; (auto-insert-mode +1)
)
(setup (:require cus-edit)
@ -142,13 +143,13 @@
(+ensure-after-init #'+key-global-mode))
(setup _work
(+with-ensure-after-init
(require '_work)))
(+with-ensure-after-init
(require '_work)))
(setup abbrev
(:option abbrev-file-name (sync/ "abbrev.el")
save-abbrevs 'silent)
(with-eval-after-load 'user-save
(with-eval-after-load 'user-save
(:with-mode edit-abbrevs-mode
(:hook #'turn-off-user-save-mode)))
(:hook-into text-mode
@ -264,6 +265,8 @@
(:option diary-file (private/ "diary")))
(setup compile
(:require +compile)
(:+key "<f5>" #'+compile-dispatch)
(:option compilation-always-kill t
compilation-ask-about-save nil
compilation-scroll-output t))
@ -301,33 +304,6 @@
(with-eval-after-load 'frowny
(add-to-list 'frowny-inhibit-modes #'dired-mode)))
(setup ecomplete (:quit)
(:load-after org-contacts)
(:also-load +ecomplete)
(:option message-mail-alias-type 'ecomplete
message-self-insert-commands nil
message-expand-name-standard-ui t)
(with-eval-after-load 'ecomplete
(:option completion-category-defaults nil)
(with-eval-after-load 'embark
(:bind-into embark-email-map
"+" #'+ecomplete-add-email
"\\" #'+ecomplete-remove-email)))
(add-hook 'message-sent-hook #'message-put-addresses-in-ecomplete))
(setup ehelp (:quit)
;; Trying this instead of `helpful'
(:global [help] 'ehelp-command
[f1] 'ehelp-command)
(with-eval-after-load 'vertico-multiform
(dolist (cmd '(electric-describe-key
electric-describe-mode
electric-describe-syntax
electric-describe-bindings
electric-describe-function
electric-describe-variable))
(setf (alist-get cmd vertico-multiform-commands) nil))))
(setup eldoc
(:hook-into elisp-mode
lisp-interaction-mode))
@ -654,14 +630,10 @@
#'turn-off-auto-fill
#'org-indent-mode
#'prettify-symbols-mode
;; TODO: This is only the beginning of a larger idea: I really want the
;; "buffer stats" section of the mode-line to change depending on the
;; mode. So like, org-mode would be a word count (maybe other text
;; modes?), lui-modes could be .... something? etc.
(defun turn-off-column-number-mode () (setq-local column-number-mode nil)))
(:local-set prettify-symbols-alist '(("DEADLINE:" . ?→)
#'+org-wrap-on-hyphens)
(:local-set prettify-symbols-alist '(("DEADLINE:" . ?→)
("SCHEDULED:" . ?↷)
("CLOSED:" ?✓))
("CLOSED:" . ?✓))
;;+modeline-position-function #'+org-count-words-stupidly
)
(:local-hook user-save-hook #'+org-before-save@prettify-buffer)
@ -885,7 +857,7 @@
(with-eval-after-load 'tramp
(el-patch-defun tramp-debug-buffer-command-completion-p (_symbol buffer)
"A predicate for Tramp interactive commands.
They are completed by \"M-x TAB\" only in Tramp debug buffers."
They are completed by \"M-x TAB\" only in Tramp debug buffers."
(with-current-buffer buffer
(el-patch-wrap 2
(save-restriction
@ -1259,6 +1231,7 @@ They are completed by \"M-x TAB\" only in Tramp debug buffers."
("C-c k" . consult-kmacro)
;; C-x bindings (ctl-x-map)
("C-x M-:" . consult-complex-command)
("<f2>" . consult-buffer)
("C-x b" . consult-buffer)
("C-x 4 b" . consult-buffer-other-window)
("C-x 5 b" . consult-buffer-other-frame)
@ -1278,6 +1251,7 @@ They are completed by \"M-x TAB\" only in Tramp debug buffers."
("M-g m" . consult-mark)
("M-g k" . consult-global-mark)
("M-g i" . consult-imenu)
("M-g M-i" . consult-imenu)
("M-g I" . consult-imenu-multi)
;; M-s bindings (search-map)
("M-s f" . consult-find)
@ -1386,8 +1360,8 @@ They are completed by \"M-x TAB\" only in Tramp debug buffers."
(el-patch-defun crux-reopen-as-root ()
"Find file as root if necessary.
Meant to be used as `find-file-hook'.
See also `crux-reopen-as-root-mode'."
Meant to be used as `find-file-hook'.
See also `crux-reopen-as-root-mode'."
(unless (or
;; This helps fix for `nov-mode', and possibly others.
(el-patch-add (null buffer-file-name))
@ -1543,18 +1517,23 @@ See also `crux-reopen-as-root-mode'."
:repo "alphapapa/ement.el")
;; `plz' is a requirement, but isn't on an elpa.
(setup (:straight (plz :host github
:repo "alphapapa/plz.el"))
:repo "alphapapa/plz.el"))
t)))
(setup (:straight epithet)
(add-hook 'epithet-suggesters #'epithet-for-eww-url)
(dolist (hook '(Info-selection-hook
eww-after-render-hook
;; eww-after-render-hook
help-mode-hook
occur-mode-hook))
(add-hook hook #'epithet-rename-buffer)))
(add-hook hook #'epithet-rename-buffer))
(if (boundp 'eww-auto-rename-buffer) ; Emacs 29
(:option eww-auto-rename-buffer 'title)
(add-hook 'eww-after-render-hook #'epithet-rename-buffer)))
(setup (:straight eros)
(:option eros-eval-result-prefix "; "
eros-overlays-use-font-lock nil)
(:hook-into emacs-lisp-mode
lisp-interaction-mode))
@ -1623,19 +1602,19 @@ See also `crux-reopen-as-root-mode'."
(:require)
(add-hook 'modus-themes-after-load-theme-hook
(defun focus-update@after-modus-load ()
(modus-themes-with-colors
(:face 'focus-unfocused `((t ( :foreground ,fg-inactive
:background ,bg-inactive
:weight normal
:slant normal
:extend t)))))))
(modus-themes-with-colors
(:face 'focus-unfocused `((t ( :foreground ,fg-inactive
:background ,bg-inactive
:weight normal
:slant normal
:extend t)))))))
;; XXX: This doesn't work, because notmuch overlays shit on the buffer
(setf (alist-get 'notmuch-show-mode focus-mode-to-thing)
'notmuch-message)
(:hook-into notmuch-show-mode))
(setup (:straight (forge
:host github :repo "magit/forge")
:host github :repo "magit/forge")
(eq system-type 'gnu/linux))
(require 'forge)
(add-to-list 'forge-alist
@ -1663,9 +1642,10 @@ See also `crux-reopen-as-root-mode'."
:pre-build ("make" "-Cdoc" "geiser.info")
:host gitlab
:repo "emacs-geiser/geiser"))
(:straight geiser-chicken)
(:straight macrostep-geiser)
(:straight scheme-complete)
(dolist (pkg '( geiser-chicken geiser-guile
macrostep-geiser
scheme-complete))
(straight-use-package pkg))
(:require +chicken)
(setf (alist-get "\\.scm\\'" auto-mode-alist nil nil #'string=)
'scheme-mode)
@ -2092,9 +2072,6 @@ See also `crux-reopen-as-root-mode'."
(advice-add 'org-modern--update-label-face :override #'ignore)
(:hook-into org-mode))
(setup (:straight org-sticky-header) (:quit)
(:hook-into org-mode))
(setup (:straight (org-taskwise
:host github
:repo "duckwork/org-taskwise.el"))

19
lisp/+compile.el Normal file
View File

@ -0,0 +1,19 @@
;;; +compile.el --- Extras for compile -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(defcustom +compile-function nil
"Function to run to \"compile\" a buffer."
:type 'function
:local t)
(defun +compile-dispatch (&optional arg)
"Run `+compile-function', if bound, or `compile'.
Any prefix ARG is passed to that function."
(interactive "P")
(call-interactively (or +compile-function #'compile)))
(provide '+compile)
;;; +compile.el ends here

View File

@ -28,44 +28,55 @@ within that group, forms with a HEAD of `:require' are sorted
first, and `:straight' HEADs are sorted last. All other forms
are sorted lexigraphically."
(interactive)
(save-excursion
(save-restriction
(widen)
(+lisp-sort-sexps
(point-min) (point-max)
;; Key function
nil
;; Sort function
(lambda (s1 s2)
(let ((s1 (cdr s1)) (s2 (cdr s2)))
(cond
;; Sort everything /not/ `setup' /before/ `setup'
((and (+init--sexp-setup-p s1)
(not (+init--sexp-setup-p s2)))
nil)
((and (+init--sexp-setup-p s2)
(not (+init--sexp-setup-p s1)))
t)
;; otherwise...
(t (let ((s1-straight (+init--sexp-setup-p s1 :straight))
(s2-straight (+init--sexp-setup-p s2 :straight))
(s1-require (+init--sexp-setup-p s1 :require))
(s2-require (+init--sexp-setup-p s2 :require)))
;; I have to make my own "version" of `save-excursion', since the mark and
;; point are lost (I think that's the problem) when sorting the buffer.
(let* ((current-point (point))
(current-defun (beginning-of-defun))
(defun-point (- current-point (point)))
(current-defun-re (buffer-substring-no-properties (line-beginning-position)
(line-end-position))))
(widen) ; It makes no sense to `save-restriction'
(+lisp-sort-sexps
(point-min) (point-max)
;; Key function
nil
;; Sort function
(lambda (s1 s2)
(let ((s1 (cdr s1)) (s2 (cdr s2)))
(cond
;; `:straight' setups have extra processing
((and s1-straight s2-straight)
(let* ((r (rx (: ":straight" (? "-when") (* space) (? "("))))
(s1 (replace-regexp-in-string r "" s1))
(s2 (replace-regexp-in-string r "" s2)))
(string< s1 s2)))
;; `:require' setups go first
((and s1-require (not s2-require)) t)
((and s2-require (not s1-require)) nil)
;; `:straight' setups go last
((and s1-straight (not s2-straight)) nil)
((and s2-straight (not s1-straight)) t)
;; otherwise, sort lexigraphically
(t (string< s1 s2))))))))))))
;; Sort everything /not/ `setup' /before/ `setup'
((and (+init--sexp-setup-p s1)
(not (+init--sexp-setup-p s2)))
nil)
((and (+init--sexp-setup-p s2)
(not (+init--sexp-setup-p s1)))
t)
;; otherwise...
(t (let ((s1-straight (+init--sexp-setup-p s1 :straight))
(s2-straight (+init--sexp-setup-p s2 :straight))
(s1-require (+init--sexp-setup-p s1 :require))
(s2-require (+init--sexp-setup-p s2 :require)))
(cond
;; `:straight' setups have extra processing
((and s1-straight s2-straight)
(let* ((r (rx (: ":straight" (? "-when") (* space) (? "("))))
(s1 (replace-regexp-in-string r "" s1))
(s2 (replace-regexp-in-string r "" s2)))
(string< s1 s2)))
;; `:require' setups go first
((and s1-require (not s2-require)) t)
((and s2-require (not s1-require)) nil)
;; `:straight' setups go last
((and s1-straight (not s2-straight)) nil)
((and s2-straight (not s1-straight)) t)
;; otherwise, sort lexigraphically
(t (string< s1 s2)))))))))
;; Return to original point relative to the defun we were in
(goto-char (point-min))
(re-search-forward current-defun-re)
(beginning-of-defun)
(goto-char (+ (point) defun-point))
))
(defun +init-sort-then-save ()
"Sort init.el, then save it."

View File

@ -649,5 +649,19 @@ and POST-PROCESS are passed to `org-export-to-file'."
(while (re-search-forward "\n\u000c\n" to t)
(org-flag-region (match-beginning 0) (match-end 0) t 'visible)))))
;;; Emacs 28+: wrap on hyphens
;; https://emacs.stackexchange.com/a/71342/37239
(defcustom +org-category-table (let ((table (copy-category-table)))
(modify-category-entry ?- ?| table)
table)
"Character category table for `org-mode'."
:type 'sexp)
(defun +org-wrap-on-hyphens ()
"Soft-wrap `org-mode' buffers on spaces and hyphens."
(set-category-table +org-category-table)
(setq-local word-wrap-by-category t))
(provide '+org)
;;; +org.el ends here

View File

@ -41,7 +41,7 @@ the filesystem, unless INHIBIT-MKDIR is non-nil."
"If MKDIR is non-nil, the directory is created.\n"
"Defined by `/define-dir'.")
(let ((file-name (expand-file-name (convert-standard-filename file)
,name)))
,name)))
(when mkdir
(make-directory (file-name-directory file-name) :parents))
file-name))))
@ -99,14 +99,20 @@ If body executes without errors, MESSAGE...Done will be displayed."
By default, act on all buffers.
Both PREDICATE and FUNC are called with no arguments, but within
a `with-current-buffer' form on the currently-active buffer."
a `with-current-buffer' form on the currently-active buffer.
As a special case, if PREDICATE is a list, it will be interpreted
as a list of major modes. In this case, FUNC will only be called
on buffers derived from one of the modes in PREDICATE."
(let ((pred (or predicate t)))
(dolist (buf (buffer-list))
(with-current-buffer buf
(when (if (or (eq (car-safe pred) 'closure)
(fboundp pred))
(funcall pred)
pred)
(when (cond ((or (eq (car-safe pred) 'closure)
(fboundp pred))
(funcall pred))
((listp pred)
(apply #'derived-mode-p pred))
(t pred))
(funcall func))))))
;; https://github.com/cstby/emacs.d/blob/main/init.el#L67
@ -289,22 +295,22 @@ always nil; this function is mostly intended for use in init."
(ignore-errors
(jabber-disconnect)))
(+with-progress "Quitting-slack..."
(dolist (team +slack-teams)
(ignore-errors
(slack-team-disconnect team)))
(ignore-errors (slack-ws-close)))
(dolist (team +slack-teams)
(ignore-errors
(slack-team-disconnect team)))
(ignore-errors (slack-ws-close)))
(+with-progress "Killing buffers..."
(ignore-errors
(+mapc-some-buffers (lambda () "Remove the buffer from tracking and kill it unconditionally."
(let ((kill-buffer-query-functions nil))
(tracking-remove-buffer (current-buffer))
(kill-buffer)))
(lambda () "Return t if derived from the following modes."
(derived-mode-p 'lui-mode
'jabber-chat-mode
'jabber-roster-mode
'jabber-browse-mode
'slack-mode))))))
(+mapc-some-buffers (lambda () "Remove the buffer from tracking and kill it unconditionally."
(let ((kill-buffer-query-functions nil))
(tracking-remove-buffer (current-buffer))
(kill-buffer)))
(lambda () "Return t if derived from the following modes."
(derived-mode-p 'lui-mode
'jabber-chat-mode
'jabber-roster-mode
'jabber-browse-mode
'slack-mode))))))
;; I can never remember all the damn chat things I run, so this just does all of em.
(defun chat (&optional arg)
@ -411,5 +417,15 @@ NOMODE will be set when called with \\[universal-argument]."
(when paste (insert paste))
(get-buffer bufname)))
(defun +indent-rigidly (arg &optional interactive)
"Indent all lines in the region, or the current line.
This calls `indent-rigidly' and passes ARG to it."
(interactive "P\np")
(unless (region-active-p)
(push-mark)
(push-mark (line-beginning-position) nil t)
(goto-char (line-end-position)))
(call-interactively #'indent-rigidly))
(provide 'acdw)
;;; acdw.el ends here