Compare commits
6 Commits
21b5d80814
...
2673a4f1d3
Author | SHA1 | Date |
---|---|---|
Case Duckworth | 2673a4f1d3 | |
Case Duckworth | 58e163e03b | |
Case Duckworth | 42947150ad | |
Case Duckworth | 4742605f98 | |
Case Duckworth | 9b2324c6e0 | |
Case Duckworth | dbb6181a5d |
225
init.el
225
init.el
|
@ -39,7 +39,8 @@
|
|||
;; ones that might not belong in a separate file.
|
||||
(:also-load +lisp)
|
||||
(:option truncate-string-ellipsis "…"
|
||||
ring-bell-function 'ignore)
|
||||
ring-bell-function 'ignore
|
||||
read-file-name-completion-ignore-case t)
|
||||
;; Bindings
|
||||
(:global "C-x C-k" #'kill-current-buffer
|
||||
"C-x 4 n" #'clone-buffer
|
||||
|
@ -53,7 +54,10 @@
|
|||
"C-<backspace>" #'+backward-kill-word
|
||||
"C-x TAB" #'+indent-rigidly
|
||||
"<f7>" #'flyspell-mode
|
||||
"C-x C-c" #'+save-buffers-quit)
|
||||
"C-x C-c" #'+save-buffers-quit
|
||||
"C-\\" nil ; original: toggle-input-method
|
||||
"C-/" #'undo-only
|
||||
"C-?" #'undo-redo)
|
||||
;; Disable bindings
|
||||
(:global "M-j" nil
|
||||
"<Scroll_Lock>" nil)
|
||||
|
@ -209,7 +213,8 @@
|
|||
(defvar +invidious-host
|
||||
;; TODO: Add variables for other transformations and what-not.
|
||||
;; ... or enable trying multiple servers
|
||||
"invidious.snopyta.org"
|
||||
;; "yewtu.be"
|
||||
"youtube.com"
|
||||
"Host for invidious instance.")
|
||||
;; Set up external browsing URLs.
|
||||
(add-to-list '+custom-variable-allowlist
|
||||
|
@ -277,6 +282,10 @@
|
|||
))
|
||||
(+browse-url-transform-url-global-mode +1))
|
||||
|
||||
(setup c-mode
|
||||
(:with-hook c-mode-common-hook
|
||||
(:hook #'indent-tabs-mode)))
|
||||
|
||||
(setup calendar
|
||||
(require '_location)
|
||||
(:option diary-file (private/ "diary")))
|
||||
|
@ -479,6 +488,9 @@
|
|||
;; (+kmacro-recording-indicator-mode +1)
|
||||
(+kmacro-block-undo-mode +1)))
|
||||
|
||||
(setup midnight
|
||||
(midnight-mode +1))
|
||||
|
||||
(setup minibuffer
|
||||
(:require +minibuffer)
|
||||
(:with-map minibuffer-local-map
|
||||
|
@ -507,20 +519,20 @@
|
|||
(:option finger-X.500-host-regexps '(".") ; only send username
|
||||
)
|
||||
(with-eval-after-load 'transient
|
||||
(transient-define-prefix net-utils ()
|
||||
"Networking utilities"
|
||||
["Actions"
|
||||
("p" "Ping" ping)
|
||||
("i" "Ifconfig" ifconfig)
|
||||
("w" "Iwconfig" iwconfig)
|
||||
("n" "Netstat" netstat)
|
||||
("a" "Arp" arp)
|
||||
("r" "Route" route)
|
||||
("h" "Nslookup host" nslookup-host)
|
||||
("d" "Dig" dig)
|
||||
("s" "Smb Client" smbclient)
|
||||
("t" "Traceroute" traceroute)])
|
||||
(:+key "C-z M-n" #'net-utils)))
|
||||
(transient-define-prefix net-utils ()
|
||||
"Networking utilities"
|
||||
["Actions"
|
||||
("p" "Ping" ping)
|
||||
("i" "Ifconfig" ifconfig)
|
||||
("w" "Iwconfig" iwconfig)
|
||||
("n" "Netstat" netstat)
|
||||
("a" "Arp" arp)
|
||||
("r" "Route" route)
|
||||
("h" "Nslookup host" nslookup-host)
|
||||
("d" "Dig" dig)
|
||||
("s" "Smb Client" smbclient)
|
||||
("t" "Traceroute" traceroute)])
|
||||
(:+key "C-z M-n" #'net-utils)))
|
||||
|
||||
(setup notmuch
|
||||
(:load-from "~/usr/share/emacs/site-lisp/")
|
||||
|
@ -660,10 +672,9 @@
|
|||
org-startup-with-inline-images t
|
||||
org-tags-column -77 ;; (- (- fill-column 1 (length org-ellipsis)))
|
||||
org-todo-keywords '((sequence "TODO(t)" "WAIT(w@/!)" "ONGOING(o@)"
|
||||
"|" "DONE(d!)")
|
||||
"|" "DONE(d!)" "ASSIGNED(a!)")
|
||||
(sequence "|" "CANCELED(k@)")
|
||||
(sequence "MEETING(m)")
|
||||
(sequence "ASSIGNED(a@/!)" "REVIEW(r)" "|" "DONE(d!)"))
|
||||
(sequence "MEETING(m)"))
|
||||
org-use-speed-commands t
|
||||
org-emphasis-alist '(("*" org-bold)
|
||||
("/" org-italic)
|
||||
|
@ -844,14 +855,18 @@
|
|||
;; from there.
|
||||
(+org-capture-templates-setf "s"
|
||||
`("SSH Config" plain (file "~/.ssh/config")
|
||||
,(concat "\n\nHost %^{Host: }"
|
||||
"\nHostname %\\1"
|
||||
"\nUser %^{User:|" (user-login-name) "}"
|
||||
"\nIdentityFile %?"
|
||||
"\nIdentitiesOnly yes"
|
||||
"\nPubkeyAuthentication yes"
|
||||
"\nPort %^{Port: |22}")
|
||||
:unnarrowed t))
|
||||
,(concat "\n\nHost %^{Host}"
|
||||
"\n Hostname %\\1"
|
||||
"\n User %^{User|%(user-login-name)}"
|
||||
"\n IdentityFile %(read-file-name \"IdentityFile: \" \"~/.ssh/\")"
|
||||
"\n IdentitiesOnly yes"
|
||||
"\n PubkeyAuthentication yes"
|
||||
"\n Port %^{Port|22}")
|
||||
))
|
||||
(+org-capture-templates-setf "r"
|
||||
`("Radio station" plain (file "~/.config/radio/stations")
|
||||
,(concat "%^{URL} %^{Description} %^{Tags [space delimited]}")
|
||||
:immediate-finish t))
|
||||
(+org-capture-sort))
|
||||
|
||||
(setup org-id
|
||||
|
@ -898,14 +913,16 @@
|
|||
(add-hook 'kill-buffer-query-functions #'+scratch-immortal))
|
||||
|
||||
(setup sh
|
||||
(:option sh-indentation tab-width)
|
||||
(:hook #'indent-tabs-mode)
|
||||
(:apheleia shfmt '("shfmt")))
|
||||
|
||||
(setup shell
|
||||
(:option shell-command-prompt-show-cwd t)
|
||||
(:local-set +modeline-position-function
|
||||
(lambda () (string-replace (getenv "HOME")
|
||||
"~"
|
||||
default-directory)))
|
||||
"~"
|
||||
default-directory)))
|
||||
(:hook #'form-feed-mode))
|
||||
|
||||
(setup shr
|
||||
|
@ -993,9 +1010,8 @@
|
|||
(:face 'aw-mode-line-face '((t (:foreground "red"))))
|
||||
(+ace-window-display-mode +1))
|
||||
|
||||
(setup (:straight (actually-selected-window
|
||||
:host github
|
||||
:repo "duckwork/actually-selected-window.el"))
|
||||
(setup (:straight (actually-selected-window :host github
|
||||
:repo "duckwork/actually-selected-window.el"))
|
||||
(actually-selected-window-mode +1))
|
||||
|
||||
(setup (:straight adaptive-wrap)
|
||||
|
@ -1121,8 +1137,7 @@
|
|||
browse-kill-ring-separator "")
|
||||
(:hook #'form-feed-mode))
|
||||
|
||||
(setup (:straight (cape
|
||||
:host github :repo "minad/cape"))
|
||||
(setup (:straight (cape :host github :repo "minad/cape"))
|
||||
(let
|
||||
;; All available cape capfs listed here. Add them to the front since
|
||||
;; they're reversed with `add-to-list'.
|
||||
|
@ -1327,9 +1342,8 @@
|
|||
(add-hook 'modus-themes-after-load-theme-hook #'circe-nick-color-reset))
|
||||
(add-hook 'kill-emacs-hook #'+circe-quit-all@kill-emacs))
|
||||
|
||||
(setup (:straight (clean-kill-ring
|
||||
:host github
|
||||
:repo "NicholasBHubbard/clean-kill-ring.el"))
|
||||
(setup (:straight (clean-kill-ring :host github
|
||||
:repo "NicholasBHubbard/clean-kill-ring.el"))
|
||||
(:require)
|
||||
(:option clean-kill-ring-prevent-duplicates t)
|
||||
(clean-kill-ring-mode +1))
|
||||
|
@ -1481,10 +1495,9 @@
|
|||
"TAB" #'dired-subtree-cycle
|
||||
"i" #'dired-subtree-toggle))
|
||||
|
||||
(setup (:straight (discord
|
||||
:host github
|
||||
:repo "davep/discord.el"
|
||||
:fork (:repo "duckwork/discord.el"))))
|
||||
(setup (:straight (discord :host github
|
||||
:repo "davep/discord.el"
|
||||
:fork (:repo "duckwork/discord.el"))))
|
||||
|
||||
(setup (:straight dumb-jump)
|
||||
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate))
|
||||
|
@ -1506,6 +1519,10 @@
|
|||
(setup (:straight editorconfig)
|
||||
(:with-mode conf-mode
|
||||
(:file-match (rx ".editorconfig" eos)))
|
||||
(dolist (m '(emacs-lisp-mode
|
||||
lisp-mode
|
||||
scheme-mode))
|
||||
(add-to-list 'editorconfig-exclude-modes m))
|
||||
(editorconfig-mode +1))
|
||||
|
||||
(setup (:straight electric-cursor)
|
||||
|
@ -1574,6 +1591,20 @@
|
|||
(file+olp ,(car rmh-elfeed-org-files) "Feeds")
|
||||
"* %? %^g")))
|
||||
|
||||
(setup (:straight (elfeed-tube :host github :repo "karthink/elfeed-tube")
|
||||
(or (executable-find "youtube-dl")
|
||||
(executable-find "yt-dlp")))
|
||||
(:straight (elfeed-tube-mpv :host github :repo "karthink/elfeed-tube"))
|
||||
(:load-after elfeed)
|
||||
(with-eval-after-load 'elfeed
|
||||
(elfeed-tube-setup)
|
||||
(:bind-into (elfeed-show-mode-map elfeed-search-mode-map)
|
||||
"F" #'elfeed-tube-fetch
|
||||
[remap save-buffer] #'elfeed-tube-save)
|
||||
(:bind-into elfeed-show-mode-map
|
||||
"C-c C-f" #'elfeed-tube-mpv-follow-mode
|
||||
"C-c C-w" #'elfeed-tube-mpv-where)))
|
||||
|
||||
(setup (:straight elpher)
|
||||
(:bind "l" #'elpher-back))
|
||||
|
||||
|
@ -1603,9 +1634,8 @@
|
|||
:inherit font-lock-keyword-face))))
|
||||
(:+key "C-," #'embrace-commander))
|
||||
|
||||
(setup (:straight (ement
|
||||
:host github
|
||||
:repo "alphapapa/ement.el")
|
||||
(setup (:straight (ement :host github
|
||||
:repo "alphapapa/ement.el")
|
||||
;; `plz' is a requirement, but isn't on an elpa.
|
||||
(setup (:straight (plz :host github
|
||||
:repo "alphapapa/plz.el"))
|
||||
|
@ -1661,20 +1691,12 @@
|
|||
(:+key "C-=" #'er/expand-region
|
||||
"C--" #'+er/contract-or-negative-argument))
|
||||
|
||||
(setup (:straight (fill-sentences-correctly
|
||||
:host github
|
||||
:repo "duckwork/fill-sentences-correctly.el"))
|
||||
(:quit "I don't think this works like how I want.")
|
||||
(fill-sentences-correctly-mode +1))
|
||||
|
||||
(setup (:straight (filldent
|
||||
:host github
|
||||
:repo "duckwork/filldent.el"))
|
||||
(setup (:straight (filldent :host nil
|
||||
:repo "https://codeberg.org/acdw/filldent.el"))
|
||||
(:+key "M-q" #'filldent-unfill-toggle))
|
||||
|
||||
(setup (:straight (flymake-collection
|
||||
:host github
|
||||
:repo "mohkale/flymake-collection"))
|
||||
(setup (:straight (flymake-collection :host github
|
||||
:repo "mohkale/flymake-collection"))
|
||||
(+ensure-after-init #'flymake-collection-hook-setup))
|
||||
|
||||
(setup (:straight (flyspell-correct
|
||||
|
@ -1702,8 +1724,7 @@
|
|||
'notmuch-message)
|
||||
(:hook-into notmuch-show-mode))
|
||||
|
||||
(setup (:straight (forge
|
||||
:host github :repo "magit/forge")
|
||||
(setup (:straight (forge :host github :repo "magit/forge")
|
||||
(eq system-type 'gnu/linux))
|
||||
(:quit) ; XXX: Somehow missing compat-26
|
||||
(add-to-list 'forge-alist
|
||||
|
@ -1715,9 +1736,8 @@
|
|||
(:face 'form-feed-line '((t (:strike-through t))))
|
||||
(global-form-feed-mode +1))
|
||||
|
||||
(setup (:straight (frowny
|
||||
:host github
|
||||
:repo "duckwork/frowny.el"))
|
||||
(setup (:straight (frowny :host nil
|
||||
:repo "https://codeberg.org/acdw/frowny.el"))
|
||||
(:option frowny-eyes (rx (any ":=") (opt "'") (? "-")))
|
||||
(global-frowny-mode +1))
|
||||
|
||||
|
@ -1738,8 +1758,7 @@
|
|||
(setf (alist-get "\\.scm\\'" auto-insert-alist nil nil #'equal)
|
||||
'(insert "#!/bin/sh\n#| -*- scheme -*-\nexec csi -s $0 \"$@\"\n|#\n")))
|
||||
|
||||
(setup (:straight (git-modes
|
||||
:host github :repo "magit/git-modes"))
|
||||
(setup (:straight (git-modes :host github :repo "magit/git-modes"))
|
||||
(:require git-modes))
|
||||
|
||||
(setup (:straight god-mode
|
||||
|
@ -1763,9 +1782,8 @@
|
|||
(require 'info-look)
|
||||
(info-lookup-setup-mode 'symbol 'emacs-lisp-mode))))
|
||||
|
||||
(setup (:straight (hippie-completing-read
|
||||
:host nil
|
||||
:repo "https://codeberg.org/acdw/hippie-completing-read.el"))
|
||||
(setup (:straight (hippie-completing-read :host nil
|
||||
:repo "https://codeberg.org/acdw/hippie-completing-read.el"))
|
||||
(:+key "M-/" #'hippie-completing-read))
|
||||
|
||||
(setup (:straight hungry-delete)
|
||||
|
@ -1825,8 +1843,8 @@
|
|||
(define-key isearch-mb-minibuffer-map (kbd key) command)))))))
|
||||
(isearch-mb-mode +1))
|
||||
|
||||
(setup (:straight (jabber :repo "https://codeberg.org/emacs-jabber/emacs-jabber"
|
||||
:host nil
|
||||
(setup (:straight (jabber :host nil
|
||||
:repo "https://codeberg.org/emacs-jabber/emacs-jabber"
|
||||
:files ("*.el" "*.texi"
|
||||
("jabber-fallback-lib"
|
||||
"jabber-fallback-lib/hexrgb.el"
|
||||
|
@ -1870,9 +1888,9 @@
|
|||
('dark 1.0)))
|
||||
(+mapc-some-buffers #'+jabber-colors-update
|
||||
(lambda () (derived-mode-p 'jabber-chat-mode
|
||||
'jabber-roster-mode
|
||||
'jabber-activity-mode
|
||||
'jabber-browse-mode)))))
|
||||
'jabber-roster-mode
|
||||
'jabber-activity-mode
|
||||
'jabber-browse-mode)))))
|
||||
(dolist (mode '(jabber-chat-mode
|
||||
jabber-browse-mode
|
||||
jabber-roster-mode
|
||||
|
@ -1896,8 +1914,8 @@
|
|||
(remove-hook 'jabber-alert-muc-hooks 'jabber-muc-echo)
|
||||
(remove-hook 'jabber-alert-presence-hooks 'jabber-presence-echo))
|
||||
|
||||
(setup (:straight (keepassxc-shim
|
||||
:host github :repo "duckwork/keepassxc-shim.el"))
|
||||
(setup (:straight (keepassxc-shim :host nil
|
||||
:repo "https://codeberg.org/acdw/keepassxc-shim.el"))
|
||||
(keepassxc-shim-activate))
|
||||
|
||||
(setup (:straight keychain-environment
|
||||
|
@ -1926,8 +1944,8 @@
|
|||
"M-c" #'+link-hint-open-chrome "c" #'+link-hint-open-chrome)))
|
||||
|
||||
(setup (:straight (machine
|
||||
:host github
|
||||
:repo "duckwork/machine.el"))
|
||||
:host nil
|
||||
:repo "https://codeberg.org/acdw/machine.el"))
|
||||
(+with-ensure-after-init ; So that they override anything here.
|
||||
;; Emoji fonts
|
||||
(let ((ffl (font-family-list))
|
||||
|
@ -1984,7 +2002,6 @@
|
|||
mastodon-tl--show-avatars t
|
||||
mastodon-tl--enable-proportional-fonts nil)
|
||||
(:hook #'mastodon-async-mode
|
||||
#'visual-fill-column-mode
|
||||
#'variable-pitch-mode
|
||||
#'hl-line-mode
|
||||
#'lin-mode))
|
||||
|
@ -2008,7 +2025,10 @@
|
|||
(:option modus-themes-mixed-fonts t
|
||||
modus-themes-bold-constructs t
|
||||
modus-themes-italic-constructs t
|
||||
modus-themes-headings '((t t)))
|
||||
modus-themes-headings '((1 monochrome bold overline)
|
||||
(2 monochrome bold)
|
||||
(3 monochrome italic)
|
||||
(t monochrome)))
|
||||
(dotimes (facen-1 8)
|
||||
(let ((facen (1+ facen-1)))
|
||||
(custom-set-faces
|
||||
|
@ -2037,6 +2057,7 @@
|
|||
:foreground unspecified)))
|
||||
`(font-lock-comment-face
|
||||
((,class :inherit variable-pitch
|
||||
:slant italic
|
||||
:foreground ,fg-comment-yellow)))
|
||||
`(font-lock-comment-delimiter-face
|
||||
((,class :inherit fixed-pitch
|
||||
|
@ -2178,26 +2199,12 @@
|
|||
(local-set-key (kbd "C-c M-o") 'org-mime-org-buffer-htmlize))))
|
||||
|
||||
(setup (:straight (org-taskwise
|
||||
:host github
|
||||
:repo "duckwork/org-taskwise.el"))
|
||||
:host nil
|
||||
:repo "https://codeberg.org/acdw/org-taskwise.el.git"))
|
||||
(with-eval-after-load 'org
|
||||
(require 'org-taskwise)
|
||||
(define-key org-mode-map (kbd "C-x n t") #'org-taskwise-narrow-to-task)))
|
||||
|
||||
(setup (:straight org-visibility)
|
||||
(:load-after org user-save)
|
||||
(:option org-visibility-state-file (.etc "org-visibility")
|
||||
org-visibility-include-regexps '("\\.org\\'"))
|
||||
(with-eval-after-load 'org-visibility
|
||||
;; I have to add these hooks myself since I don't want it triggering on
|
||||
;; /every/ save, but just when I `user-save'.
|
||||
(add-hook 'user-save-hook #'org-visibility-save-noerror :append)
|
||||
(add-hook 'kill-buffer-hook #'org-visibility-save-noerror :append)
|
||||
(add-hook 'kill-emacs-hook #'org-visibility-save-all-buffers :append)
|
||||
(add-hook 'find-file-hook #'org-visibility-load :append)
|
||||
(add-hook 'first-change-hook #'org-visibility-dirty :append)
|
||||
(add-hook 'org-cycle-hook #'org-visibility-dirty-org-cycle :append)))
|
||||
|
||||
(setup (:straight org-wc)
|
||||
(:load-after org simple-modeline)
|
||||
(:also-load +org-wc)
|
||||
|
@ -2264,9 +2271,8 @@
|
|||
persistent-scratch-scratch-buffer-p-function))
|
||||
|
||||
(setup (:straight (plancat
|
||||
:host github
|
||||
:repo "duckwork/plancat.el"
|
||||
:local-repo "~/src/emacs-packages/plancat.el/"))
|
||||
:host nil
|
||||
:repo "https://codeberg.org/acdw/plancat.el"))
|
||||
(:option plancat-user "acdw"))
|
||||
|
||||
(setup (:straight pocket-reader)
|
||||
|
@ -2287,8 +2293,6 @@
|
|||
(setup (:straight rainbow-mode)
|
||||
(:hook-into prog-mode))
|
||||
|
||||
(setup (:straight restart-emacs))
|
||||
|
||||
(setup (:straight (shell-command+
|
||||
:host nil
|
||||
:repo "https://git.sr.ht/~pkal/shell-command-plus"))
|
||||
|
@ -2375,8 +2379,8 @@
|
|||
(:hook-into prog-mode))
|
||||
|
||||
(setup (:straight (sophomore
|
||||
:host github
|
||||
:repo "duckwork/sophomore.el"))
|
||||
:host nil
|
||||
:repo "https://codeberg.org/acdw/sophomore.el"))
|
||||
(sophomore-enable #'narrow-to-region)
|
||||
(sophomore-disable ; These are mostly annoying commands
|
||||
#'view-hello-file
|
||||
|
@ -2389,8 +2393,8 @@
|
|||
(sophomore-mode +1))
|
||||
|
||||
(setup (:straight (spongebob-case
|
||||
:host github
|
||||
:repo "duckwork/spongebob-case.el")))
|
||||
:host nil
|
||||
:repo "https://codeberg.org/acdw/spongebob-case.el")))
|
||||
|
||||
(setup (:straight ssh-config-mode)
|
||||
(:file-match (rx "/.ssh/config" eos)
|
||||
|
@ -2414,10 +2418,13 @@
|
|||
(:option systemd-man-function 'woman))
|
||||
|
||||
(setup (:straight (titlecase
|
||||
:host github
|
||||
:repo "duckwork/titlecase.el"
|
||||
:host nil
|
||||
:repo "https://codeberg.org/acdw/titlecase.el"
|
||||
:files ("*")))
|
||||
(:require titlecase +titlecase)
|
||||
(add-to-list 'titlecase-skip-words-regexps (rx word-boundary
|
||||
(+ (any upper digit))
|
||||
word-boundary))
|
||||
(:with-map +casing-map
|
||||
(:bind "t" #'titlecase-dwim
|
||||
"M-t" #'titlecase-dwim
|
||||
|
@ -2466,10 +2473,10 @@
|
|||
(:option twtxt-file _twtxt-file
|
||||
twtxt-following _twtxt-following))
|
||||
|
||||
(setup (:straight undo-fu)
|
||||
(:option undo-fu-allow-undo-in-region t)
|
||||
(:global "C-/" #'undo-fu-only-undo
|
||||
"C-?" #'undo-fu-only-redo))
|
||||
(setup (:straight undo-fu) (:quit "Trying native undo functionality")
|
||||
(:option undo-fu-allow-undo-in-region t)
|
||||
(:global "C-/" #'undo-fu-only-undo
|
||||
"C-?" #'undo-fu-only-redo))
|
||||
|
||||
(setup (:straight undo-fu-session)
|
||||
(:option undo-fu-session-incompatible-files '("/COMMIT_EDITMSG\\'"
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
;;; +compat.el --- Thin backward-compatibility shim -*- lexical-binding: t; -*-
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; I use different versionso of Emacs. Sometimes I have to copy-paste functions
|
||||
;; from newer Emacs to make my customizations work. This is that file.
|
||||
|
||||
;; This is probably ill-advised.
|
||||
|
||||
;;; Code:
|
||||
|
||||
;;; Load stuff in +compat/ subdirectory
|
||||
(dolist (file (directory-files (locate-user-emacs-file "lisp/+compat") :full "\\.el\\'"))
|
||||
(load file :noerror))
|
||||
|
||||
;;; Only define things if not already defined
|
||||
(defmacro +compat-defun (name &rest args)
|
||||
`(if (fboundp ',name)
|
||||
(message "+compat: `%s' already bound." ',name)
|
||||
(defun ,name ,@args)))
|
||||
|
||||
(defmacro +compat-defmacro (name &rest args)
|
||||
`(if (fboundp ',name)
|
||||
(message "+compat: `%s' already bound." ',name)
|
||||
(defmacro ,name ,@args)))
|
||||
|
||||
;;; Single functions
|
||||
|
||||
(+compat-defmacro dlet (binders &rest body)
|
||||
"Like `let' but using dynamic scoping."
|
||||
(declare (indent 1) (debug let))
|
||||
;; (defvar FOO) only affects the current scope, but in order for
|
||||
;; this not to affect code after the main `let' we need to create a new scope,
|
||||
;; which is what the surrounding `let' is for.
|
||||
;; FIXME: (let () ...) currently doesn't actually create a new scope,
|
||||
;; which is why we use (let (_) ...).
|
||||
`(let (_)
|
||||
,@(mapcar (lambda (binder)
|
||||
`(defvar ,(if (consp binder) (car binder) binder)))
|
||||
binders)
|
||||
(let ,binders ,@body)))
|
||||
|
||||
;; https://git.savannah.gnu.org/cgit/emacs.git/diff/?id=772b189143453745a8e014e21d4b6b78f855bba3
|
||||
(+compat-defun rename-visited-file (new-location)
|
||||
"Rename the file visited by the current buffer to NEW-LOCATION.
|
||||
This command also sets the visited file name. If the buffer
|
||||
isn't visiting any file, that's all it does.
|
||||
|
||||
Interactively, this prompts for NEW-LOCATION."
|
||||
(interactive
|
||||
(list (if buffer-file-name
|
||||
(read-file-name "Rename visited file to: ")
|
||||
(read-file-name "Set visited file name: "
|
||||
default-directory
|
||||
(expand-file-name
|
||||
(file-name-nondirectory (buffer-name))
|
||||
default-directory)))))
|
||||
(when (and buffer-file-name
|
||||
(file-exists-p buffer-file-name))
|
||||
(rename-file buffer-file-name new-location))
|
||||
(set-visited-file-name new-location nil t))
|
||||
|
||||
(provide '+compat)
|
||||
;;; +compat.el ends here
|
|
@ -206,8 +206,17 @@ Do this only if the buffer is not visiting a file."
|
|||
|
||||
;;; Hooks
|
||||
|
||||
(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
|
||||
(add-hook 'minibuffer-setup-hook 'cursor-intangible-mode)
|
||||
(add-hook 'after-save-hook #'executable-make-buffer-file-executable-if-script-p)
|
||||
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
|
||||
|
||||
(defun +auto-create-missing-dirs ()
|
||||
"Automatically create missing directories when finding a file."
|
||||
;; https://emacsredux.com/blog/2022/06/12/auto-create-missing-directories/
|
||||
(let ((target-dir (file-name-directory buffer-file-name)))
|
||||
(unless (file-exists-p target-dir)
|
||||
(make-directory target-dir t))))
|
||||
|
||||
(add-hook 'find-file-not-found-functions #'+auto-create-missing-dirs)
|
||||
|
||||
|
||||
;;; Better-default functions ...
|
||||
|
|
73
lisp/+org.el
73
lisp/+org.el
|
@ -729,5 +729,78 @@ When called with a prefix ARG, will still unconditionally call
|
|||
((org-at-table-p) #'org-table-wrap-region)
|
||||
(t #'org-return)))))
|
||||
|
||||
|
||||
;;; move org archives to a dedicated file
|
||||
(defun +org-archive-monthwise (archive-file)
|
||||
(if (file-exists-p archive-file)
|
||||
(with-current-buffer (find-file-noselect archive-file)
|
||||
(let ((dir (file-name-directory (file-truename archive-file)))
|
||||
(prog (make-progress-reporter (format "Archiving from %s..." archive-file)))
|
||||
(keep-going t))
|
||||
(goto-char (point-min))
|
||||
(while keep-going
|
||||
(when-let* ((time (or (org-entry-get (point) "ARCHIVE_TIME")
|
||||
(org-get-deadline-time (point))))
|
||||
(parsed-time (and time
|
||||
(org-parse-time-string time)))
|
||||
(refile-target (format "%s%02d-%02d.org"
|
||||
dir
|
||||
(decoded-time-year parsed-time)
|
||||
(decoded-time-month parsed-time)))
|
||||
(title-str (format "#+title: Archive for %02d-%02d (%s)\n\n"
|
||||
(decoded-time-year parsed-time)
|
||||
(decoded-time-month parsed-time)
|
||||
(file-truename archive-file))))
|
||||
(unless (file-exists-p refile-target)
|
||||
(with-current-buffer (find-file-noselect refile-target)
|
||||
(insert title-str)
|
||||
(save-buffer)))
|
||||
(org-refile nil nil (list ""
|
||||
refile-target
|
||||
nil
|
||||
0)))
|
||||
(progress-reporter-update prog)
|
||||
(org-next-visible-heading 1)
|
||||
(when (>= (point) (point-max))
|
||||
(setq keep-going nil)))))
|
||||
(message "Archive file %s does not exist!" archive-file)))
|
||||
|
||||
|
||||
;;; el-patch
|
||||
|
||||
(el-patch-defun org-format-outline-path (path &optional width prefix separator)
|
||||
"Format the outline path PATH for display.
|
||||
WIDTH is the maximum number of characters that is available.
|
||||
PREFIX is a prefix to be included in the returned string,
|
||||
such as the file name.
|
||||
SEPARATOR is inserted between the different parts of the path,
|
||||
the default is \"/\"."
|
||||
(setq width (or width 79))
|
||||
(setq path (delq nil path))
|
||||
(unless (> width 0)
|
||||
(user-error "Argument `width' must be positive"))
|
||||
(setq separator (or separator "/"))
|
||||
(let* ((org-odd-levels-only nil)
|
||||
(fpath (concat
|
||||
prefix (and prefix path separator)
|
||||
(mapconcat
|
||||
(lambda (s) (replace-regexp-in-string "[ \t]+\\'" "" s))
|
||||
(cl-loop for head in path
|
||||
for n from 0
|
||||
collect (el-patch-swap
|
||||
(org-add-props
|
||||
head nil 'face
|
||||
(nth (% n org-n-level-faces) org-level-faces))
|
||||
head))
|
||||
separator))))
|
||||
(when (> (length fpath) width)
|
||||
(if (< width 7)
|
||||
;; It's unlikely that `width' will be this small, but don't
|
||||
;; waste characters by adding ".." if it is.
|
||||
(setq fpath (substring fpath 0 width))
|
||||
(setf (substring fpath (- width 2)) "..")))
|
||||
fpath))
|
||||
|
||||
|
||||
(provide '+org)
|
||||
;;; +org.el ends here
|
||||
|
|
|
@ -4,10 +4,14 @@
|
|||
|
||||
;;; Code:
|
||||
|
||||
(defun +titlecase-sentence-style-dwim ()
|
||||
"Titlecase a sentence."
|
||||
(interactive)
|
||||
(titlecase-dwim 'sentence))
|
||||
(defun +titlecase-sentence-style-dwim (&optional arg)
|
||||
"Titlecase a sentence.
|
||||
With prefix ARG, toggle the value of
|
||||
`titlecase-downcase-sentences' before sentence-casing."
|
||||
(interactive "P")
|
||||
(let ((titlecase-downcase-sentences (if arg (not titlecase-downcase-sentences)
|
||||
titlecase-downcase-sentences)))
|
||||
(titlecase-dwim 'sentence)))
|
||||
|
||||
(defun +titlecase-org-headings ()
|
||||
(interactive)
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
;;; compat.el --- Thin backward-compatibility shim -*- lexical-binding: t; -*-
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; I use different versionso of Emacs. Sometimes I have to copy-paste functions
|
||||
;; from newer Emacs to make my customizations work. This is that file.
|
||||
|
||||
;; This is probably ill-advised.
|
||||
|
||||
;;; Code:
|
||||
|
||||
;; Load stuff in compat/ subdirectory
|
||||
(dolist (file (directory-files (locate-user-emacs-file "lisp/compat") :full "\\.el\\'"))
|
||||
(load file :noerror))
|
||||
|
||||
;; Other stuff...
|
||||
|
||||
(unless (fboundp 'dlet)
|
||||
(defmacro dlet (binders &rest body)
|
||||
"Like `let' but using dynamic scoping."
|
||||
(declare (indent 1) (debug let))
|
||||
;; (defvar FOO) only affects the current scope, but in order for
|
||||
;; this not to affect code after the main `let' we need to create a new scope,
|
||||
;; which is what the surrounding `let' is for.
|
||||
;; FIXME: (let () ...) currently doesn't actually create a new scope,
|
||||
;; which is why we use (let (_) ...).
|
||||
`(let (_)
|
||||
,@(mapcar (lambda (binder)
|
||||
`(defvar ,(if (consp binder) (car binder) binder)))
|
||||
binders)
|
||||
(let ,binders ,@body))))
|
||||
|
||||
(provide 'compat)
|
||||
;;; compat.el ends here
|
|
@ -1,590 +0,0 @@
|
|||
;;; keymap.el --- Keymap functions -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2021-2022 Free Software Foundation, Inc.
|
||||
|
||||
;; This file is part of GNU Emacs.
|
||||
|
||||
;; GNU Emacs 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.
|
||||
|
||||
;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; This library deals with the "new" keymap binding interface: The
|
||||
;; only key syntax allowed by these functions is the `kbd' one.
|
||||
|
||||
;;; Code:
|
||||
|
||||
|
||||
|
||||
(defun keymap--check (key)
|
||||
"Signal an error if KEY doesn't have a valid syntax."
|
||||
(unless (key-valid-p key)
|
||||
(error "%S is not a valid key definition; see `key-valid-p'" key)))
|
||||
|
||||
(defun keymap--compile-check (&rest keys)
|
||||
(dolist (key keys)
|
||||
(when (or (vectorp key)
|
||||
(and (stringp key) (not (key-valid-p key))))
|
||||
(byte-compile-warn "Invalid `kbd' syntax: %S" key))))
|
||||
|
||||
(defun keymap-set (keymap key definition)
|
||||
"Set KEY to DEFINITION in KEYMAP.
|
||||
KEY is a string that satisfies `key-valid-p'.
|
||||
|
||||
DEFINITION is anything that can be a key's definition:
|
||||
nil (means key is undefined in this keymap),
|
||||
a command (a Lisp function suitable for interactive calling),
|
||||
a string (treated as a keyboard macro),
|
||||
a keymap (to define a prefix key),
|
||||
a symbol (when the key is looked up, the symbol will stand for its
|
||||
function definition, which should at that time be one of the above,
|
||||
or another symbol whose function definition is used, etc.),
|
||||
a cons (STRING . DEFN), meaning that DEFN is the definition
|
||||
(DEFN should be a valid definition in its own right) and
|
||||
STRING is the menu item name (which is used only if the containing
|
||||
keymap has been created with a menu name, see `make-keymap'),
|
||||
or a cons (MAP . CHAR), meaning use definition of CHAR in keymap MAP,
|
||||
or an extended menu item definition.
|
||||
(See info node `(elisp)Extended Menu Items'.)"
|
||||
(declare (compiler-macro (lambda (form) (keymap--compile-check key) form)))
|
||||
(keymap--check key)
|
||||
;; If we're binding this key to another key, then parse that other
|
||||
;; key, too.
|
||||
(when (stringp definition)
|
||||
(keymap--check definition)
|
||||
(setq definition (key-parse definition)))
|
||||
(define-key keymap (key-parse key) definition))
|
||||
|
||||
(defun keymap-global-set (key command)
|
||||
"Give KEY a global binding as COMMAND.
|
||||
COMMAND is the command definition to use; usually it is
|
||||
a symbol naming an interactively-callable function.
|
||||
|
||||
KEY is a string that satisfies `key-valid-p'.
|
||||
|
||||
Note that if KEY has a local binding in the current buffer,
|
||||
that local binding will continue to shadow any global binding
|
||||
that you make with this function."
|
||||
(declare (compiler-macro (lambda (form) (keymap--compile-check key) form)))
|
||||
(interactive
|
||||
(let* ((menu-prompting nil)
|
||||
(key (read-key-sequence "Set key globally: " nil t)))
|
||||
(list key
|
||||
(read-command (format "Set key %s to command: "
|
||||
(key-description key))))))
|
||||
(keymap-set (current-global-map) key command))
|
||||
|
||||
(defun keymap-local-set (key command)
|
||||
"Give KEY a local binding as COMMAND.
|
||||
COMMAND is the command definition to use; usually it is
|
||||
a symbol naming an interactively-callable function.
|
||||
|
||||
KEY is a string that satisfies `key-valid-p'.
|
||||
|
||||
The binding goes in the current buffer's local map, which in most
|
||||
cases is shared with all other buffers in the same major mode."
|
||||
(declare (compiler-macro (lambda (form) (keymap--compile-check key) form)))
|
||||
(interactive "KSet key locally: \nCSet key %s locally to command: ")
|
||||
(let ((map (current-local-map)))
|
||||
(unless map
|
||||
(use-local-map (setq map (make-sparse-keymap))))
|
||||
(keymap-set map key command)))
|
||||
|
||||
(defun keymap-global-unset (key &optional remove)
|
||||
"Remove global binding of KEY (if any).
|
||||
KEY is a string that satisfies `key-valid-p'.
|
||||
|
||||
If REMOVE (interactively, the prefix arg), remove the binding
|
||||
instead of unsetting it. See `keymap-unset' for details."
|
||||
(declare (compiler-macro (lambda (form) (keymap--compile-check key) form)))
|
||||
(interactive
|
||||
(list (key-description (read-key-sequence "Set key locally: "))
|
||||
current-prefix-arg))
|
||||
(keymap-unset (current-global-map) key remove))
|
||||
|
||||
(defun keymap-local-unset (key &optional remove)
|
||||
"Remove local binding of KEY (if any).
|
||||
KEY is a string that satisfies `key-valid-p'.
|
||||
|
||||
If REMOVE (interactively, the prefix arg), remove the binding
|
||||
instead of unsetting it. See `keymap-unset' for details."
|
||||
(declare (compiler-macro (lambda (form) (keymap--compile-check key) form)))
|
||||
(interactive
|
||||
(list (key-description (read-key-sequence "Unset key locally: "))
|
||||
current-prefix-arg))
|
||||
(when (current-local-map)
|
||||
(keymap-unset (current-local-map) key remove)))
|
||||
|
||||
(defun keymap-unset (keymap key &optional remove)
|
||||
"Remove key sequence KEY from KEYMAP.
|
||||
KEY is a string that satisfies `key-valid-p'.
|
||||
|
||||
If REMOVE, remove the binding instead of unsetting it. This only
|
||||
makes a difference when there's a parent keymap. When unsetting
|
||||
a key in a child map, it will still shadow the same key in the
|
||||
parent keymap. Removing the binding will allow the key in the
|
||||
parent keymap to be used."
|
||||
(declare (compiler-macro (lambda (form) (keymap--compile-check key) form)))
|
||||
(keymap--check key)
|
||||
(define-key keymap (key-parse key) nil remove))
|
||||
|
||||
(defun keymap-substitute (keymap olddef newdef &optional oldmap prefix)
|
||||
"Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF.
|
||||
In other words, OLDDEF is replaced with NEWDEF wherever it appears.
|
||||
Alternatively, if optional fourth argument OLDMAP is specified, we redefine
|
||||
in KEYMAP as NEWDEF those keys that are defined as OLDDEF in OLDMAP.
|
||||
|
||||
If you don't specify OLDMAP, you can usually get the same results
|
||||
in a cleaner way with command remapping, like this:
|
||||
(define-key KEYMAP [remap OLDDEF] NEWDEF)
|
||||
\n(fn OLDDEF NEWDEF KEYMAP &optional OLDMAP)"
|
||||
;; Don't document PREFIX in the doc string because we don't want to
|
||||
;; advertise it. It's meant for recursive calls only. Here's its
|
||||
;; meaning
|
||||
|
||||
;; If optional argument PREFIX is specified, it should be a key
|
||||
;; prefix, a string. Redefined bindings will then be bound to the
|
||||
;; original key, with PREFIX added at the front.
|
||||
(unless prefix
|
||||
(setq prefix ""))
|
||||
(let* ((scan (or oldmap keymap))
|
||||
(prefix1 (vconcat prefix [nil]))
|
||||
(key-substitution-in-progress
|
||||
(cons scan key-substitution-in-progress)))
|
||||
;; Scan OLDMAP, finding each char or event-symbol that
|
||||
;; has any definition, and act on it with hack-key.
|
||||
(map-keymap
|
||||
(lambda (char defn)
|
||||
(aset prefix1 (length prefix) char)
|
||||
(substitute-key-definition-key defn olddef newdef prefix1 keymap))
|
||||
scan)))
|
||||
|
||||
(defun keymap-set-after (keymap key definition &optional after)
|
||||
"Add binding in KEYMAP for KEY => DEFINITION, right after AFTER's binding.
|
||||
This is like `keymap-set' except that the binding for KEY is placed
|
||||
just after the binding for the event AFTER, instead of at the beginning
|
||||
of the map. Note that AFTER must be an event type (like KEY), NOT a command
|
||||
\(like DEFINITION).
|
||||
|
||||
If AFTER is t or omitted, the new binding goes at the end of the keymap.
|
||||
AFTER should be a single event type--a symbol or a character, not a sequence.
|
||||
|
||||
Bindings are always added before any inherited map.
|
||||
|
||||
The order of bindings in a keymap matters only when it is used as
|
||||
a menu, so this function is not useful for non-menu keymaps."
|
||||
(declare (indent defun)
|
||||
(compiler-macro (lambda (form) (keymap--compile-check key) form)))
|
||||
(keymap--check key)
|
||||
(when after
|
||||
(keymap--check after))
|
||||
(define-key-after keymap (key-parse key) definition
|
||||
(and after (key-parse after))))
|
||||
|
||||
(defun key-parse (keys)
|
||||
"Convert KEYS to the internal Emacs key representation.
|
||||
See `kbd' for a descripion of KEYS."
|
||||
(declare (pure t) (side-effect-free t))
|
||||
;; A pure function is expected to preserve the match data.
|
||||
(save-match-data
|
||||
(let ((case-fold-search nil)
|
||||
(len (length keys)) ; We won't alter keys in the loop below.
|
||||
(pos 0)
|
||||
(res []))
|
||||
(while (and (< pos len)
|
||||
(string-match "[^ \t\n\f]+" keys pos))
|
||||
(let* ((word-beg (match-beginning 0))
|
||||
(word-end (match-end 0))
|
||||
(word (substring keys word-beg len))
|
||||
(times 1)
|
||||
key)
|
||||
;; Try to catch events of the form "<as df>".
|
||||
(if (string-match "\\`<[^ <>\t\n\f][^>\t\n\f]*>" word)
|
||||
(setq word (match-string 0 word)
|
||||
pos (+ word-beg (match-end 0)))
|
||||
(setq word (substring keys word-beg word-end)
|
||||
pos word-end))
|
||||
(when (string-match "\\([0-9]+\\)\\*." word)
|
||||
(setq times (string-to-number (substring word 0 (match-end 1))))
|
||||
(setq word (substring word (1+ (match-end 1)))))
|
||||
(cond ((string-match "^<<.+>>$" word)
|
||||
(setq key (vconcat (if (eq (key-binding [?\M-x])
|
||||
'execute-extended-command)
|
||||
[?\M-x]
|
||||
(or (car (where-is-internal
|
||||
'execute-extended-command))
|
||||
[?\M-x]))
|
||||
(substring word 2 -2) "\r")))
|
||||
((and (string-match "^\\(\\([ACHMsS]-\\)*\\)<\\(.+\\)>$" word)
|
||||
(progn
|
||||
(setq word (concat (match-string 1 word)
|
||||
(match-string 3 word)))
|
||||
(not (string-match
|
||||
"\\<\\(NUL\\|RET\\|LFD\\|ESC\\|SPC\\|DEL\\)$"
|
||||
word))))
|
||||
(setq key (list (intern word))))
|
||||
((or (equal word "REM") (string-match "^;;" word))
|
||||
(setq pos (string-match "$" keys pos)))
|
||||
(t
|
||||
(let ((orig-word word) (prefix 0) (bits 0))
|
||||
(while (string-match "^[ACHMsS]-." word)
|
||||
(setq bits (+ bits
|
||||
(cdr
|
||||
(assq (aref word 0)
|
||||
'((?A . ?\A-\^@) (?C . ?\C-\^@)
|
||||
(?H . ?\H-\^@) (?M . ?\M-\^@)
|
||||
(?s . ?\s-\^@) (?S . ?\S-\^@))))))
|
||||
(setq prefix (+ prefix 2))
|
||||
(setq word (substring word 2)))
|
||||
(when (string-match "^\\^.$" word)
|
||||
(setq bits (+ bits ?\C-\^@))
|
||||
(setq prefix (1+ prefix))
|
||||
(setq word (substring word 1)))
|
||||
(let ((found (assoc word '(("NUL" . "\0") ("RET" . "\r")
|
||||
("LFD" . "\n") ("TAB" . "\t")
|
||||
("ESC" . "\e") ("SPC" . " ")
|
||||
("DEL" . "\177")))))
|
||||
(when found (setq word (cdr found))))
|
||||
(when (string-match "^\\\\[0-7]+$" word)
|
||||
(let ((n 0))
|
||||
(dolist (ch (cdr (string-to-list word)))
|
||||
(setq n (+ (* n 8) ch -48)))
|
||||
(setq word (vector n))))
|
||||
(cond ((= bits 0)
|
||||
(setq key word))
|
||||
((and (= bits ?\M-\^@) (stringp word)
|
||||
(string-match "^-?[0-9]+$" word))
|
||||
(setq key (mapcar (lambda (x) (+ x bits))
|
||||
(append word nil))))
|
||||
((/= (length word) 1)
|
||||
(error "%s must prefix a single character, not %s"
|
||||
(substring orig-word 0 prefix) word))
|
||||
((and (/= (logand bits ?\C-\^@) 0) (stringp word)
|
||||
;; We used to accept . and ? here,
|
||||
;; but . is simply wrong,
|
||||
;; and C-? is not used (we use DEL instead).
|
||||
(string-match "[@-_a-z]" word))
|
||||
(setq key (list (+ bits (- ?\C-\^@)
|
||||
(logand (aref word 0) 31)))))
|
||||
(t
|
||||
(setq key (list (+ bits (aref word 0)))))))))
|
||||
(when key
|
||||
(dolist (_ (number-sequence 1 times))
|
||||
(setq res (vconcat res key))))))
|
||||
(if (and (>= (length res) 4)
|
||||
(eq (aref res 0) ?\C-x)
|
||||
(eq (aref res 1) ?\()
|
||||
(eq (aref res (- (length res) 2)) ?\C-x)
|
||||
(eq (aref res (- (length res) 1)) ?\)))
|
||||
(apply #'vector (let ((lres (append res nil)))
|
||||
;; Remove the first and last two elements.
|
||||
(setq lres (cdr (cdr lres)))
|
||||
(nreverse lres)
|
||||
(setq lres (cdr (cdr lres)))
|
||||
(nreverse lres)))
|
||||
res))))
|
||||
|
||||
(defun key-valid-p (keys)
|
||||
"Say whether KEYS is a valid key.
|
||||
A key is a string consisting of one or more key strokes.
|
||||
The key strokes are separated by single space characters.
|
||||
|
||||
Each key stroke is either a single character, or the name of an
|
||||
event, surrounded by angle brackets. In addition, any key stroke
|
||||
may be preceded by one or more modifier keys. Finally, a limited
|
||||
number of characters have a special shorthand syntax.
|
||||
|
||||
Here's some example key sequences.
|
||||
|
||||
\"f\" (the key 'f')
|
||||
\"S o m\" (a three key sequence of the keys 'S', 'o' and 'm')
|
||||
\"C-c o\" (a two key sequence of the keys 'c' with the control modifier
|
||||
and then the key 'o')
|
||||
\"H-<left>\" (the key named \"left\" with the hyper modifier)
|
||||
\"M-RET\" (the \"return\" key with a meta modifier)
|
||||
\"C-M-<space>\" (the \"space\" key with both the control and meta modifiers)
|
||||
|
||||
These are the characters that have shorthand syntax:
|
||||
NUL, RET, TAB, LFD, ESC, SPC, DEL.
|
||||
|
||||
Modifiers have to be specified in this order:
|
||||
|
||||
A-C-H-M-S-s
|
||||
|
||||
which is
|
||||
|
||||
Alt-Control-Hyper-Meta-Shift-super"
|
||||
(declare (pure t) (side-effect-free t))
|
||||
(and
|
||||
(stringp keys)
|
||||
(string-match-p "\\`[^ ]+\\( [^ ]+\\)*\\'" keys)
|
||||
(save-match-data
|
||||
(catch 'exit
|
||||
(let ((prefixes
|
||||
"\\(A-\\)?\\(C-\\)?\\(H-\\)?\\(M-\\)?\\(S-\\)?\\(s-\\)?")
|
||||
(case-fold-search nil))
|
||||
(dolist (key (split-string keys " "))
|
||||
;; Every key might have these modifiers, and they should be
|
||||
;; in this order.
|
||||
(when (string-match (concat "\\`" prefixes) key)
|
||||
(setq key (substring key (match-end 0))))
|
||||
(unless (or (and (= (length key) 1)
|
||||
;; Don't accept control characters as keys.
|
||||
(not (< (aref key 0) ?\s))
|
||||
;; Don't accept Meta'd characters as keys.
|
||||
(or (multibyte-string-p key)
|
||||
(not (<= 127 (aref key 0) 255))))
|
||||
(and (string-match-p "\\`<[-_A-Za-z0-9]+>\\'" key)
|
||||
;; Don't allow <M-C-down>.
|
||||
(= (progn
|
||||
(string-match
|
||||
(concat "\\`<" prefixes) key)
|
||||
(match-end 0))
|
||||
1))
|
||||
(string-match-p
|
||||
"\\`\\(NUL\\|RET\\|TAB\\|LFD\\|ESC\\|SPC\\|DEL\\)\\'"
|
||||
key))
|
||||
;; Invalid.
|
||||
(throw 'exit nil)))
|
||||
t)))))
|
||||
|
||||
(defun key-translate (from to)
|
||||
"Translate character FROM to TO on the current terminal.
|
||||
This function creates a `keyboard-translate-table' if necessary
|
||||
and then modifies one entry in it.
|
||||
|
||||
Both KEY and TO are strings that satisfy `key-valid-p'."
|
||||
(declare (compiler-macro
|
||||
(lambda (form) (keymap--compile-check from to) form)))
|
||||
(keymap--check from)
|
||||
(keymap--check to)
|
||||
(or (char-table-p keyboard-translate-table)
|
||||
(setq keyboard-translate-table
|
||||
(make-char-table 'keyboard-translate-table nil)))
|
||||
(aset keyboard-translate-table (key-parse from) (key-parse to)))
|
||||
|
||||
(defun keymap-lookup (keymap key &optional accept-default no-remap position)
|
||||
"Return the binding for command KEY.
|
||||
KEY is a string that satisfies `key-valid-p'.
|
||||
|
||||
If KEYMAP is nil, look up in the current keymaps. If non-nil, it
|
||||
should either be a keymap or a list of keymaps, and only these
|
||||
keymap(s) will be consulted.
|
||||
|
||||
The binding is probably a symbol with a function definition.
|
||||
|
||||
Normally, `keymap-lookup' ignores bindings for t, which act as
|
||||
default bindings, used when nothing else in the keymap applies;
|
||||
this makes it usable as a general function for probing keymaps.
|
||||
However, if the optional second argument ACCEPT-DEFAULT is
|
||||
non-nil, `keymap-lookup' does recognize the default bindings,
|
||||
just as `read-key-sequence' does.
|
||||
|
||||
Like the normal command loop, `keymap-lookup' will remap the
|
||||
command resulting from looking up KEY by looking up the command
|
||||
in the current keymaps. However, if the optional third argument
|
||||
NO-REMAP is non-nil, `keymap-lookup' returns the unmapped
|
||||
command.
|
||||
|
||||
If KEY is a key sequence initiated with the mouse, the used keymaps
|
||||
will depend on the clicked mouse position with regard to the buffer
|
||||
and possible local keymaps on strings.
|
||||
|
||||
If the optional argument POSITION is non-nil, it specifies a mouse
|
||||
position as returned by `event-start' and `event-end', and the lookup
|
||||
occurs in the keymaps associated with it instead of KEY. It can also
|
||||
be a number or marker, in which case the keymap properties at the
|
||||
specified buffer position instead of point are used."
|
||||
(declare (compiler-macro (lambda (form) (keymap--compile-check key) form)))
|
||||
(keymap--check key)
|
||||
(when (and keymap position)
|
||||
(error "Can't pass in both keymap and position"))
|
||||
(if keymap
|
||||
(let ((value (lookup-key keymap (key-parse key) accept-default)))
|
||||
(if (and (not no-remap)
|
||||
(symbolp value))
|
||||
(or (command-remapping value) value)
|
||||
value))
|
||||
(key-binding (kbd key) accept-default no-remap position)))
|
||||
|
||||
(defun keymap-local-lookup (keys &optional accept-default)
|
||||
"Return the binding for command KEYS in current local keymap only.
|
||||
KEY is a string that satisfies `key-valid-p'.
|
||||
|
||||
The binding is probably a symbol with a function definition.
|
||||
|
||||
If optional argument ACCEPT-DEFAULT is non-nil, recognize default
|
||||
bindings; see the description of `keymap-lookup' for more details
|
||||
about this."
|
||||
(declare (compiler-macro (lambda (form) (keymap--compile-check keys) form)))
|
||||
(when-let ((map (current-local-map)))
|
||||
(keymap-lookup map keys accept-default)))
|
||||
|
||||
(defun keymap-global-lookup (keys &optional accept-default message)
|
||||
"Return the binding for command KEYS in current global keymap only.
|
||||
KEY is a string that satisfies `key-valid-p'.
|
||||
|
||||
The binding is probably a symbol with a function definition.
|
||||
This function's return values are the same as those of `keymap-lookup'
|
||||
\(which see).
|
||||
|
||||
If optional argument ACCEPT-DEFAULT is non-nil, recognize default
|
||||
bindings; see the description of `keymap-lookup' for more details
|
||||
about this.
|
||||
|
||||
If MESSAGE (and interactively), message the result."
|
||||
(declare (compiler-macro (lambda (form) (keymap--compile-check keys) form)))
|
||||
(interactive
|
||||
(list (key-description (read-key-sequence "Look up key in global keymap: "))
|
||||
nil t))
|
||||
(let ((def (keymap-lookup (current-global-map) keys accept-default)))
|
||||
(when message
|
||||
(message "%s is bound to %s globally" keys def))
|
||||
def))
|
||||
|
||||
|
||||
;;; define-keymap and defvar-keymap
|
||||
|
||||
(defun define-keymap--compile (form &rest args)
|
||||
;; This compiler macro is only there for compile-time
|
||||
;; error-checking; it does not change the call in any way.
|
||||
(while (and args
|
||||
(keywordp (car args))
|
||||
(not (eq (car args) :menu)))
|
||||
(unless (memq (car args) '(:full :keymap :parent :suppress :name :prefix))
|
||||
(byte-compile-warn "Invalid keyword: %s" (car args)))
|
||||
(setq args (cdr args))
|
||||
(when (null args)
|
||||
(byte-compile-warn "Uneven number of keywords in %S" form))
|
||||
(setq args (cdr args)))
|
||||
;; Bindings.
|
||||
(while args
|
||||
(let ((key (pop args)))
|
||||
(when (and (stringp key) (not (key-valid-p key)))
|
||||
(byte-compile-warn "Invalid `kbd' syntax: %S" key)))
|
||||
(when (null args)
|
||||
(byte-compile-warn "Uneven number of key bindings in %S" form))
|
||||
(setq args (cdr args)))
|
||||
form)
|
||||
|
||||
(defun define-keymap (&rest definitions)
|
||||
"Create a new keymap and define KEY/DEFINITION pairs as key bindings.
|
||||
The new keymap is returned.
|
||||
|
||||
Options can be given as keywords before the KEY/DEFINITION
|
||||
pairs. Available keywords are:
|
||||
|
||||
:full If non-nil, create a chartable alist (see `make-keymap').
|
||||
If nil (i.e., the default), create a sparse keymap (see
|
||||
`make-sparse-keymap').
|
||||
|
||||
:suppress If non-nil, the keymap will be suppressed (see `suppress-keymap').
|
||||
If `nodigits', treat digits like other chars.
|
||||
|
||||
:parent If non-nil, this should be a keymap to use as the parent
|
||||
(see `set-keymap-parent').
|
||||
|
||||
:keymap If non-nil, instead of creating a new keymap, the given keymap
|
||||
will be destructively modified instead.
|
||||
|
||||
:name If non-nil, this should be a string to use as the menu for
|
||||
the keymap in case you use it as a menu with `x-popup-menu'.
|
||||
|
||||
:prefix If non-nil, this should be a symbol to be used as a prefix
|
||||
command (see `define-prefix-command'). If this is the case,
|
||||
this symbol is returned instead of the map itself.
|
||||
|
||||
KEY/DEFINITION pairs are as KEY and DEF in `keymap-set'. KEY can
|
||||
also be the special symbol `:menu', in which case DEFINITION
|
||||
should be a MENU form as accepted by `easy-menu-define'.
|
||||
|
||||
\(fn &key FULL PARENT SUPPRESS NAME PREFIX KEYMAP &rest [KEY DEFINITION]...)"
|
||||
(declare (indent defun)
|
||||
(compiler-macro define-keymap--compile))
|
||||
(let (full suppress parent name prefix keymap)
|
||||
;; Handle keywords.
|
||||
(while (and definitions
|
||||
(keywordp (car definitions))
|
||||
(not (eq (car definitions) :menu)))
|
||||
(let ((keyword (pop definitions)))
|
||||
(unless definitions
|
||||
(error "Missing keyword value for %s" keyword))
|
||||
(let ((value (pop definitions)))
|
||||
(pcase keyword
|
||||
(:full (setq full value))
|
||||
(:keymap (setq keymap value))
|
||||
(:parent (setq parent value))
|
||||
(:suppress (setq suppress value))
|
||||
(:name (setq name value))
|
||||
(:prefix (setq prefix value))
|
||||
(_ (error "Invalid keyword: %s" keyword))))))
|
||||
|
||||
(when (and prefix
|
||||
(or full parent suppress keymap))
|
||||
(error "A prefix keymap can't be defined with :full/:parent/:suppress/:keymap keywords"))
|
||||
|
||||
(when (and keymap full)
|
||||
(error "Invalid combination: :keymap with :full"))
|
||||
|
||||
(let ((keymap (cond
|
||||
(keymap keymap)
|
||||
(prefix (define-prefix-command prefix nil name))
|
||||
(full (make-keymap name))
|
||||
(t (make-sparse-keymap name)))))
|
||||
(when suppress
|
||||
(suppress-keymap keymap (eq suppress 'nodigits)))
|
||||
(when parent
|
||||
(set-keymap-parent keymap parent))
|
||||
|
||||
;; Do the bindings.
|
||||
(while definitions
|
||||
(let ((key (pop definitions)))
|
||||
(unless definitions
|
||||
(error "Uneven number of key/definition pairs"))
|
||||
(let ((def (pop definitions)))
|
||||
(if (eq key :menu)
|
||||
(easy-menu-define nil keymap "" def)
|
||||
(keymap-set keymap key def)))))
|
||||
keymap)))
|
||||
|
||||
(defmacro defvar-keymap (variable-name &rest defs)
|
||||
"Define VARIABLE-NAME as a variable with a keymap definition.
|
||||
See `define-keymap' for an explanation of the keywords and KEY/DEFINITION.
|
||||
|
||||
In addition to the keywords accepted by `define-keymap', this
|
||||
macro also accepts a `:doc' keyword, which (if present) is used
|
||||
as the variable documentation string.
|
||||
|
||||
\(fn VARIABLE-NAME &key DOC FULL PARENT SUPPRESS NAME PREFIX KEYMAP &rest [KEY DEFINITION]...)"
|
||||
(declare (indent 1))
|
||||
(let ((opts nil)
|
||||
doc)
|
||||
(while (and defs
|
||||
(keywordp (car defs))
|
||||
(not (eq (car defs) :menu)))
|
||||
(let ((keyword (pop defs)))
|
||||
(unless defs
|
||||
(error "Uneven number of keywords"))
|
||||
(if (eq keyword :doc)
|
||||
(setq doc (pop defs))
|
||||
(push keyword opts)
|
||||
(push (pop defs) opts))))
|
||||
(unless (zerop (% (length defs) 2))
|
||||
(error "Uneven number of key/definition pairs: %s" defs))
|
||||
`(defvar ,variable-name
|
||||
(define-keymap ,@(nreverse opts) ,@defs)
|
||||
,@(and doc (list doc)))))
|
||||
|
||||
(provide 'keymap)
|
||||
|
||||
;;; keymap.el ends here
|
File diff suppressed because it is too large
Load Diff
|
@ -8,33 +8,38 @@
|
|||
(require 'machine)
|
||||
|
||||
(defun +bob-set-faces (&rest _)
|
||||
(let ((base-face "IBM Plex Mono")
|
||||
(base-size 110)
|
||||
(let (;;(base-face "IBM Plex Mono")
|
||||
;; (var-face "IBM Plex Sans")
|
||||
;; (base-face "Iosevka Comfy Wide")
|
||||
;; (var-face "Iosevka Comfy Duo")
|
||||
(base-face "DejaVu Sans Mono")
|
||||
(var-face "DejaVu Sans")
|
||||
(base-size 100)
|
||||
(var-size 1.0)
|
||||
(italic-face nil)
|
||||
;; (bold-face nil)
|
||||
(mono-face nil)
|
||||
(var-face "IBM Plex Sans")
|
||||
(var-size 1.0))
|
||||
(mono-face nil))
|
||||
(+set-faces
|
||||
`((default
|
||||
:family ,base-face
|
||||
:height ,base-size
|
||||
:weight normal)
|
||||
;; (bold :family ,(or bold-face base-face)
|
||||
;; :weight bold)
|
||||
(italic :family ,(or italic-face base-face)
|
||||
:weight regular)
|
||||
(bold :family ,(or (bound-and-true-p bold-face) base-face)
|
||||
:weight extra-bold)
|
||||
(italic :family ,(or (bound-and-true-p italic-face) base-face)
|
||||
:weight normal
|
||||
:slant italic)
|
||||
(fixed-pitch :family ,(or mono-face base-face)
|
||||
(fixed-pitch :family ,(or (bound-and-true-p mono-face) base-face)
|
||||
:height 1.0)
|
||||
(variable-pitch
|
||||
:family ,(or var-face base-face)
|
||||
:height ,var-size)
|
||||
(org-italic
|
||||
:family ,(or var-face base-face)
|
||||
:slant italic)))))
|
||||
;; (org-italic
|
||||
;; :family ,(or var-face base-face)
|
||||
;; :slant italic)
|
||||
))))
|
||||
|
||||
;; Other ideas: [[https://twitter.com/NPRougier/status/1488570192561160195][from Nic Rougier]]
|
||||
(add-function :after machine-after-load-theme #'+bob-set-faces)
|
||||
(add-hook 'machine-after-load-theme-hook #'+bob-set-faces)
|
||||
|
||||
;; bob.el ends here (+bob-set-faces)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# ~/.emacs
|
||||
|
||||
This is my Emacs config. There are many like it, but this one is mine.
|
||||
|
||||
(If you're reading this from tildegit, I've moved to [my own server now](https://git.acdw.net/emacs/).)
|
16
readme.txt
16
readme.txt
|
@ -1,16 +0,0 @@
|
|||
<h1>~/.emacs</h1>
|
||||
<p>
|
||||
This is my Emacs config.
|
||||
There are many like it, but this one is mine.
|
||||
|
||||
<h2>interesting bits</h2>
|
||||
<p>
|
||||
|
||||
Check out the <code>lisp/</code> folder, there's a bunch of cool stuff there.
|
||||
My <code>early-init.el</code> is pretty static, but interesting stuff happens in
|
||||
<code>init.el</code>.
|
||||
|
||||
<p>
|
||||
|
||||
(If you're reading this from tildegit, I've moved to <a
|
||||
href="https://git.acdw.net/emacs/">my own server now</a>.)
|
Loading…
Reference in New Issue