#+PROPERTY: header-args:emacs-lisp :tangle yes :results silent :export code
* Introduction
-:PROPERTIES:
-:ID: 92e3c7e3-febf-46ac-ae1b-650d57c31240
-:END:
This is my emacs configuration. It is meant to be used across linux, windows, and BSD. I use windows only at work (Industrial Controls). I use emacs often as an advanced programmable calculator.
Lots of inspiration taken from:
- [[https://github.com/sachac/.emacs.d][github.com/sachac/.emacs.d]]
** A note on version checking
-:PROPERTIES:
-:ID: 6ff82e4f-1e11-43d5-afca-8cf905eea937
-:END:
I keep my emacs installs at the latest release, so I don't worry about checking for versions in my init unless I happen to update on linux/BSD before the windows binaries are released. That being said, I am currently on version 29.3.
** Latinization
-:PROPERTIES:
-:ID: 7afb5b82-e888-483b-9988-7fbc50839cb6
-:END:
I believe that all scientific knowledge, and by extension computational knowledge, should be shared in Latin. That is to say I intend to facilitate Latin's return as the default language for global knowledge sharing. To be consistent, I will soon be translating as much of this file as possible into Latin. Monitus es.
* Meta Configuration
-:PROPERTIES:
-:ID: edd4ed35-bf17-46ce-96a1-4c78aed06c1e
-:END:
I have taken this mostly whole-hog from [[https://github.com/larstvei/dot-emacs][github.com/larstvei/dot-emacs]]. The idea is that this bare-bones init.el is available when the repo is pulled in, but gets overwritten on emacs' first run. Emacs will need to be re-started after that initial run, since =early-init.el= will be created, and some packages will be installed.
** Init.el
-:PROPERTIES:
-:ID: e0f3f2eb-a3ad-4c60-963f-263d07f3a98c
-:END:
This is the repo's =init.el= file, which bootstraps the real =init.el=.
#+BEGIN_SRC emacs-lisp :tangle no
;;; This file replaces itself with the real config at first run
#+END_SRC
** Git init.el tracking
-:PROPERTIES:
-:ID: 2d505071-c9ca-4747-bf5a-7543b50f053e
-:END:
*** Disable Tracking
-:PROPERTIES:
-:ID: 524b42ee-76a1-4061-a6a9-55106c4167ed
-:END:
There is no reason to track the =init.el= that is generated. Run the following command to make git ignore the generated file, but keep the dummy init.
#+BEGIN_SRC sh :tangle no
git update-index --assume-unchanged init.el
#+END_SRC
*** Enable Tracking
-:PROPERTIES:
-:ID: 5adcac01-ab6a-4556-a160-06c2498d61e5
-:END:
If changes to the dummy-init are needed, track those by running
#+BEGIN_SRC sh :tangle no
git update-index --no-assume-unchanged init.el
#+END_SRC
* Early init
-:PROPERTIES:
-:ID: 4420cd35-3101-4ee2-bc61-964e08b06174
-:END:
This file was introduced in Emacs 27. I use it for speeding up init, removing all the UI stuff I don't want, etc. Maybe superfluous, but I do get startup times on the order of /0.015/ seconds. No longer superfluous, because this is where you set up the items needed for android emacs to play nice with termux - see [[https://sourceforge.net/projects/android-ports-for-gnu-emacs/files/termux][SourceForge]]
** The normal header
-:PROPERTIES:
-:ID: 994087b6-1707-4cc2-9555-988ae9d4a51d
-:END:
There are no GNU Police (yet), but I feel nicer by adding this in.
#+BEGIN_SRC emacs-lisp :tangle ./early-init.el
;;; early-init.el -*- lexical-binding: t; -*-
#+END_SRC
** Android Setup
-:PROPERTIES:
-:ID: df50b909-93f9-4e98-981e-fdc396c28f28
-:END:
Version 30.0 brings android support - let's try it out. This makes emacs play nice with termux. See [[https://sourceforge.net/projects/android-ports-for-gnu-emacs/files/termux][SourceForge]].
#+BEGIN_SRC emacs-lisp :tangle ./early-init.el
(when (equal system-type 'android)
#+END_SRC
** GC thrashing
-:PROPERTIES:
-:ID: d95e3549-b3ad-4aeb-a229-739a871b6c4b
-:END:
Set the GC threshold to max during startup, then set it back to a value that is somewhat more sane than the default /800kb/.
#+BEGIN_SRC emacs-lisp :tangle ./early-init.el
#+END_SRC
** Basic UI preferences
-:PROPERTIES:
-:ID: c60bc3a8-d04a-4cbd-8039-fee1e2ecf9ee
-:END:
I want no menus, no tool-bars, left-side scroll-bars, no blinking cursor, no messages when starting up, make resizing work properly, and start up maximized. I just want the scratch buffer with a report on =emacs-init-time=.
#+BEGIN_SRC emacs-lisp :tangle ./early-init.el
(menu-bar-mode -1)
#+END_SRC
** Misc/odd issues
-:PROPERTIES:
-:ID: 086a73ac-b883-4783-aa87-e6ad3ac54398
-:END:
Avoid a weird issue on windows where opening emacs via an [[https://www.autohotkey.com/][AutoHotKey]] binding causes emacs to load in the AutoHotKey directory.
#+BEGIN_SRC emacs-lisp :tangle ./early-init.el
#+END_SRC
** The normal footer
-:PROPERTIES:
-:ID: ae3aa94e-27f2-4845-b306-effae05c79ac
-:END:
#+BEGIN_SRC emacs-lisp :tangle ./early-init.el
(provide 'early-init)
#+END_SRC
* Main init
-:PROPERTIES:
-:ID: fabe0435-21bb-4336-bd5d-01a7344265a9
-:END:
** Header
-:PROPERTIES:
-:ID: 33be7f35-74f6-4d1d-bf58-673a7a475665
-:END:
#+BEGIN_SRC emacs-lisp
;;; init.el --- Quae configurare -*- lexical-binding: t; -*-
#+END_SRC
** Packages
-:PROPERTIES:
-:ID: dff50446-ba25-48d0-a126-75bc8a1087e3
-:END:
Load packages first, so there is no question about dependencies later in the file.
*** Package Repositories
-:PROPERTIES:
-:ID: 43c60653-1584-4ba5-8dfd-358b96897b33
-:END:
Non-gnu is in the defaults now, so I only need to add melpa.
#+BEGIN_SRC emacs-lisp
#+END_SRC
*** Packages I don't want on my work computers
-:PROPERTIES:
-:ID: 659c9663-b387-45d5-8386-c3a356b3766e
-:END:
I don't need these on a windows PC or android.
#+BEGIN_SRC emacs-lisp
(unless (or (equal system-type 'windows-nt)
#+END_SRC
*** visual-fill-column
-:PROPERTIES:
-:ID: ffbdc9f9-4ec4-401f-9f97-1e0d74b72c49
-:END:
A godsend. Finally, I can have visual-line-mode without having to read lines that are 1980 pixels wide! Also set word wrap, and make the split for help do what I want on big screens.
#+BEGIN_SRC emacs-lisp
#+END_SRC
*** corfu
-:PROPERTIES:
-:ID: 13511ed2-bc09-469d-b71a-2c8a082f65fc
-:END:
I used =company-mode= for a long time. I tried corfu and haven't looked back. It is smaller, and does everything I was doing with company.
**** Main Corfu
-:PROPERTIES:
-:ID: 86e4a1b4-7734-42de-a5fc-aca9ea93d532
-:END:
The basics for corfu. Auto popup after one letter, enable globally.
#+BEGIN_SRC emacs-lisp
#+END_SRC
**** corfu-popupinfo
-:PROPERTIES:
-:ID: da81efaa-3669-4700-90cb-2e95c434a453
-:END:
This comes with base corfu, but is configured separately.
#+BEGIN_SRC emacs-lisp
#+END_SRC
*** expand-region
-:PROPERTIES:
-:ID: 3cdd5e3a-2f7d-4c12-8b77-1f8f6f6ed494
-:END:
Seldom used, but nothing else does it.
#+BEGIN_SRC emacs-lisp
#+END_SRC
*** magit
-:PROPERTIES:
-:ID: 2af0acc8-e7fb-47d4-9bd8-fa1edd18a1b4
-:END:
I use magit occasionally. I put this sparse configuration here mostly for a speed boost, by making magit only load when I explicitly call for it.
#+BEGIN_SRC emacs-lisp
#+END_SRC
*** openwith
-:PROPERTIES:
-:ID: d5826618-b99b-4f71-b6f5-58ec937924d9
-:END:
I need to open binary files with their own editor. Disgusting.
#+BEGIN_SRC emacs-lisp
#+END_SRC
*** acme-mouse
-:PROPERTIES:
-:ID: 936ffd88-1955-4d84-ad96-fb1744d5a6e9
-:END:
Not a package in the strict sense, just a .el file loaded as a git submodule - forked from [[https://github.com/akrito/acme-mouse/]] to [[https://github.com/rearman/acme-mouse/]] and modified to meet changes to the old =cl= package, and to fix the ~mouse-3~ search function. Also see the [[id:451a20e6-73a0-4d55-aeaa-e795980a6974][Maus]] section.
#+BEGIN_SRC emacs-lisp
(unless (equal system-type 'android)
#+END_SRC
*** AUCTeX
-:PROPERTIES:
-:ID: 3053fb45-ac60-4c80-9041-ba5afb9dfaa0
-:END:
Starting to do some work with LaTeX, surprised this is not in base, but org is.
#+BEGIN_SRC emacs-lisp
(use-package auctex
#+END_SRC
*** SLIME
-:PROPERTIES:
-:ID: 2e6c92be-b509-42fd-8595-e28369fc2c13
-:END:
Lisp me
#+BEGIN_SRC emacs-lisp
(load (expand-file-name "~/quicklisp/slime-helper.el"))
#+END_SRC
** Non-Package customization
-:PROPERTIES:
-:ID: 6488cb21-1bb0-4b7d-93fb-c04dc4e04024
-:END:
This section has '/base/' emacs customization. All the general stuff.
*** Defaults
-:PROPERTIES:
-:ID: 6319f5d5-0763-4e41-a67b-90fb18d77e80
-:END:
I want these things every time, or at least setting them this way worked when a regular =setq= didn't.
#+BEGIN_SRC emacs-lisp
#+END_SRC
*** UTF-8
-:PROPERTIES:
-:ID: 79eb9b8c-84a3-4dcb-808f-ef7ff26eb829
-:END:
Force emacs to use UTF-8 so I avoid prompts on save
#+BEGIN_SRC emacs-lisp
(set-language-environment 'utf-8)
#+END_SRC
*** Backup/Autosave
-:PROPERTIES:
-:ID: caa6e592-9e74-42a7-837a-f7c650a43b11
-:END:
I originally had some autosave items in here, but the defaults appeared to be doing basically what I wanted anyway.
**** Backups
-:PROPERTIES:
-:ID: 64316516-6335-403d-9045-fb565466fca6
-:END:
Make backups for vc-controlled files, don't clobber symlinks, and put everything into =~/emacs-backups/=.
#+BEGIN_SRC emacs-lisp
(setq vc-make-backup-files t
#+END_SRC
**** Old versions
-:PROPERTIES:
-:ID: 03c827f2-b478-40fa-8b29-81ef6661811f
-:END:
Keep 10 versions, 5 'old' and 5 'new'. Delete anything older.
#+BEGIN_SRC emacs-lisp
(setq delete-old-versions t
#+END_SRC
*** File handling
-:PROPERTIES:
-:ID: 871b5b3f-d905-48b1-a305-036dccfc3df5
-:END:
**** Final Newline
-:PROPERTIES:
-:ID: 34ddec70-6977-4f2d-bd72-b0a240d659ec
-:END:
I want to avoid ever seeing an error about missing newlines at the end of a file.
#+BEGIN_SRC emacs-lisp
(setq require-final-newline t)
#+END_SRC
**** Auto Revert
-:PROPERTIES:
-:ID: 6d36da61-2373-433c-a7df-cc62511ee1ad
-:END:
When files change on disk, and there are no changes in the open buffer, revert to the on-disk version.
#+BEGIN_SRC emacs-lisp
(global-auto-revert-mode t)
#+END_SRC
**** Segfault recovery
-:PROPERTIES:
-:ID: e014f4e7-c131-463c-9d8f-f16530faea83
-:END:
These are directly from [[https://depp.brause.cc/dotemacs/][depp.brause.cc/dotemacs/]]. They are intended to make Emacs drop changes and die when a segfault happens, rather than attempt to save potentially corrupted data.
#+BEGIN_SRC emacs-lisp
(setq attempt-stack-overflow-recovery nil
#+END_SRC
**** Whitespace and chmod on save
-:PROPERTIES:
-:ID: 2375de4d-f558-47f1-aea1-581240a0039a
-:END:
I want to strip all trailing whitespace on save, and I want to make all shell scripts executable at the same time.
#+BEGIN_SRC emacs-lisp
(add-hook 'before-save-hook 'whitespace-cleanup)
#+END_SRC
*** Minibuffer interaction
-:PROPERTIES:
-:ID: 32d9a1c6-7890-4d05-b241-5dcb83e9b848
-:END:
I don't want emacs to beep or blink at me, I want y/n instead of the default yes/no, I don't care for clicking on things in the minibuffer, I like seeing things echoed almost immediately, for keystrokes and eldoc. I want eldoc to stick to one line. I want history to only show me unique commands, and I want case-insensitive buffer switching.
#+BEGIN_SRC emacs-lisp
#+END_SRC
*** Buffer interaction
-:PROPERTIES:
-:ID: 3961ab16-6a8f-4706-9511-4e26db0d4853
-:END:
**** General
-:PROPERTIES:
-:ID: 3cd5a48b-92b4-47fb-a203-9d460a583d09
-:END:
Close unused buffers after 3 days.
#+BEGIN_SRC emacs-lisp
(midnight-mode t)
#+END_SRC
*** Buffer looks
-:PROPERTIES:
-:ID: 225b0716-b552-4166-b71f-0b54256a08a8
-:END:
**** Prettify Symbols
-:PROPERTIES:
-:ID: f221ed0a-d6ec-4182-a80c-76d6bf186d0f
-:END:
I want nice symbols to look at
#+BEGIN_SRC emacs-lisp
(setq prettify-symbols-alist '(("lambda" . 955)
#+END_SRC
**** Visual Line Mode indicators
-:PROPERTIES:
-:ID: 16667fd4-a437-4bc1-9d84-3f5cd622ece6
-:END:
Show arrows when a line wraps
#+BEGIN_SRC emacs-lisp
(setq-default visual-line-fringe-indicators '(left-curly-arrow right-curly-arrow))
#+END_SRC
**** Scroll Bars
-:PROPERTIES:
-:ID: 58205491-d6a1-4f60-aed4-3430ed8be3c0
-:END:
Put my scroll bars where I like them.
#+BEGIN_SRC emacs-lisp
(set-scroll-bar-mode 'left)
#+END_SRC
*** Parens
-:PROPERTIES:
-:ID: de1b05fb-6127-485d-a4f2-2d2476e0fc4c
-:END:
When I'm on a beginning/ending paren, I find the default of only highlighting the parens too hard to see, and highlighting the whole thing too garish. Therefore, this setup tries to underline the expression, with minimal highlighting.
Show matching parens immediately, and "highlight" the whole expression.
#+END_SRC
*** Modeline
-:PROPERTIES:
-:ID: cf373f6a-1f7a-4b97-b5a3-a216ab5b0b31
-:END:
Funny name for the frame
#+BEGIN_SRC emacs-lisp
(setq frame-title-format "Poor Man's LispM")
#+END_SRC
*** C-Style
-:PROPERTIES:
-:ID: ffea9a43-63e9-42f8-8b3d-6d2b4339b667
-:END:
Please use Tabs in C files, I'm BEGGING. Absolutely ridiculous that there's no simple variable to select Tabs ONLY for indentation.
#+BEGIN_SRC emacs-lisp
(defun re/c-lineup-arglist-tabs-only (ignored)
#+END_SRC
*** Windows-Specific
-:PROPERTIES:
-:ID: 609a563c-bcdf-4ac0-94de-ce6601db7460
-:END:
Use =recycle bin=, DON'T use =AltGr=, and tell emacs where =diff= is.
#+BEGIN_SRC emacs-lisp
(when (equal system-type 'windows-nt)
#+END_SRC
** Defuns and Bindings
-:PROPERTIES:
-:ID: c9362b6e-5e89-4d4c-b358-58236816f698
-:END:
I have quite a few math and work-related defuns, and fewer editing ones. Inversely, I have more editing related bindings than work-related ones. This makes sense, considering my usage patterns.
*** Editing
-:PROPERTIES:
-:ID: e235c02e-dfdd-41c3-93ec-42f44594488f
-:END:
Most of these are to re-create something from vim/readline/sam/acme. Some are just helper functions or wrappers.
**** Visiting Files
-:PROPERTIES:
-:ID: 9f4775e4-6c76-46d6-b4e0-7dbce717907a
-:END:
Bind ~find-file-at-point~ and ~bookmark-jump-other-window~.
#+BEGIN_SRC emacs-lisp
(keymap-global-set "C-x M-f" 'find-file-at-point)
#+END_SRC
**** Undo/redo
-:PROPERTIES:
-:ID: da7cd3d7-1b85-48d3-8f68-e6b496e184ea
-:END:
I like putting redo on ~C-\~. Easier for me to remember than the ~C-M-_~ default.
#+BEGIN_SRC emacs-lisp
(keymap-global-set "C-\\" 'undo-redo)
#+END_SRC
**** Renaming Files
-:PROPERTIES:
-:ID: 11b46ac1-befc-4920-8672-24a01333ca1f
-:END:
I took this from [[https://whattheemacsd.com][whattheemacsd.com]]. It is occasionally handy.
#+BEGIN_SRC emacs-lisp
(defun re/rename-current-buffer-file ()
(keymap-global-set "C-x C-r" 're/rename-current-buffer-file)
#+END_SRC
**** Buffer Menu
-:PROPERTIES:
-:ID: 485c4ac3-839f-4289-a4c9-43da1a3ae048
-:END:
Usually I want the buffer menu in the same window I am already on. Occasionally I want it in a different window. Bind accordingly.
#+BEGIN_SRC emacs-lisp
(keymap-global-set "C-x C-b" 'buffer-menu)
#+END_SRC
**** Switch to Scratch
-:PROPERTIES:
-:ID: 2d37f85a-de5a-408c-a6ce-4b8078a95775
-:END:
I often want to bring up the scratch buffer in my current window, and sometimes I want only one window that is the scratch buffer. Emacs 29 added the ~scratch-buffer~ function, so one less defun needed here.
#+BEGIN_SRC emacs-lisp
(defun re/scratch-only ()
#+END_SRC
**** Line joining
-:PROPERTIES:
-:ID: 76950919-72fc-4d2c-becf-9ef702b906f1
-:END:
The ~M-^~ binding is handy, but usually I want the ed/sam/vi join function, which pulls the next line up into the current line. I bind this to ~M-j~.
#+BEGIN_SRC emacs-lisp
(defun re/backward-join-line ()
#+END_SRC
**** Line opening
-:PROPERTIES:
-:ID: fb7d3259-0e5c-4330-9da9-14c5c1f051e8
-:END:
The default behavior of =open-line= is ridiculous. It acheives the same function as hitting =RET=. I don't want to split the current line, I want to OPEN a new one, and usually go to it. These wrappers remedy that.
#+BEGIN_SRC emacs-lisp
#+END_SRC
**** Commenting
-:PROPERTIES:
-:ID: eb1fa08e-66f0-4620-9e93-eed42fe770b7
-:END:
I stole this directly from [[https://depp.brause.cc/dotemacs][depp.brause.cc/dotemacs]]. Very good, simple solution.
#+BEGIN_SRC emacs-lisp
(defun re/comment-dwim ()
#+END_SRC
**** Killing
-:PROPERTIES:
-:ID: 4b90fe0e-ffe5-4aca-b46b-9fd9980bda69
-:END:
***** Kill Whole Line
-:PROPERTIES:
-:ID: ed167953-3a6c-4dce-9045-372c6c73cd00
-:END:
Bind =kill-whole-line= to =C-S-K= for something somewhat pnemonic.
#+BEGIN_SRC emacs-lisp
(keymap-global-set "C-S-K" 'kill-whole-line)
#+END_SRC
***** Zap up to char
-:PROPERTIES:
-:ID: 44c6ede5-89a0-496c-9a1f-d0d1e69ad727
-:END:
Bind =C-z= to zap-up-to-char, sice zap-to-char is on =M-z=.
#+BEGIN_SRC emacs-lisp
(keymap-global-set "C-z" 'zap-up-to-char)
#+END_SRC
***** UNIX C-w and C-u
-:PROPERTIES:
-:ID: 80589df3-9a23-4b2c-b103-9263db7efaab
-:END:
=C-w= is very much engrained for killing back one word, as is =C-u= for killing back to the beginning of the line. [[http://unix-kb.cat-v.org/][These have been standard bindings since TENEX...]]
****** =C-w=
-:PROPERTIES:
-:ID: dd0452c4-59c0-4c05-9ace-8988f28d736d
-:END:
I didn't want to re-bind =C-w= away from =kill-region=, so I made it do both.
#+BEGIN_SRC emacs-lisp
#+END_SRC
****** =C-u=
-:PROPERTIES:
-:ID: 6bd8af3f-f277-4328-9037-020c9529a1ee
-:END:
There is no pre-made function to kill backward to the beginning of line from point, so I made one that passes the correct argument to =kill-line=, and bound it to =C-u=.
#+BEGIN_SRC emacs-lisp
#+END_SRC
**** Moving
-:PROPERTIES:
-:ID: e8c8fd42-e96a-4804-8ce0-6e3ab4d9233d
-:END:
***** Home/End
-:PROPERTIES:
-:ID: 9f81584b-4ce1-48ff-b69f-b0bab2c1d0c5
-:END:
I want =Home= and =End= to take me to the top and bottom of the file.
#+BEGIN_SRC emacs-lisp
(keymap-global-set "<home>" 'beginning-of-buffer)
#+END_SRC
***** Beginning of line
-:PROPERTIES:
-:ID: e8ddfa3d-4be7-4da7-bf6a-5dee3fcac91f
-:END:
****** ~smart-beginning-of-line~
-:PROPERTIES:
-:ID: 7b9d4bde-5ed4-4618-899e-4a0a82359f7f
-:END:
I have the infamous =smart-beginning-of-line= command here.
#+BEGIN_SRC emacs-lisp
(defun re/smart-beginning-of-line ()
(beginning-of-line))))
#+END_SRC
****** Play nice with ~visual-line-mode~
-:PROPERTIES:
-:ID: c8ad20f0-755c-4075-ae97-a43d4869cca9
-:END:
I had issues with ~smart-beginning-of-line~ in ~visual-line-mode~, so ~smart-beginning-of-visual-line~ was created. It implements part of ~back-to-indentation~, but with changes to use ~beginning-of-visual-line~ instead of ~beginning-of-line~.
#+BEGIN_SRC emacs-lisp
(defun re/smart-beginning-of-visual-line ()
(beginning-of-visual-line))))
#+END_SRC
****** Re-mappings
-:PROPERTIES:
-:ID: 4a8e9670-2783-4f4a-ada7-f1837a8632be
-:END:
Remap =move-beginning-of-line=, then remap =beginning-of-visual-line= when going into =visual-line-mode=. A simple remap would not work for =visual-line-mode=, so I explicitly set =C-a=.
#+BEGIN_SRC emacs-lisp
(global-set-key [remap move-beginning-of-line] 're/smart-beginning-of-line)
(keymap-global-set "C-a" 're/smart-beginning-of-visual-line)))
#+END_SRC
***** Line Numbers on move only
-:PROPERTIES:
-:ID: 2a73fd23-0869-4d5b-b727-8fa2486dc99b
-:END:
I don't want line numbers in the margin unless I am actively trying to go to a line. I override =goto-line= with this function, which shows line numbers, asks me where I want to go, and then hides line numbers.
#+BEGIN_SRC emacs-lisp
(defun re/goto-line ()
(global-set-key [remap goto-line] 're/goto-line)
#+END_SRC
***** Other window or split window
-:PROPERTIES:
-:ID: 7e9a99eb-18fd-4254-a20c-a1cb2fe0584d
-:END:
I ripped this defun and binding from [[https://github.com/lem-project/lem][lem]]. Can't live without it now. Does similar things as [[id:1c8d7229-796f-446a-8ae8-247cd6164a12][Windmove]], but without having to specify a direction.
#+BEGIN_SRC emacs-lisp
(defun re/other-window-or-split-window (&optional window)
(keymap-global-set "C-M-o" 're/other-window-or-split-window)
#+END_SRC
**** Search and Replace
-:PROPERTIES:
-:ID: 32daa74b-39b2-4275-bd88-55e9f9d0ffb5
-:END:
I made these bindings to put my more-used commands on better keys, and swap them with the less-used ones. Also add bindings for ~isearch-*-regexp~.
#+BEGIN_SRC emacs-lisp
(keymap-global-set "M-s ." 'isearch-forward-thing-at-point)
#+END_SRC
**** Insert Key
-:PROPERTIES:
-:ID: cf443c0b-3799-4fe7-817f-a35f614fe336
-:END:
I keep accidentally enabling ~overwrite-mode~, so disable the ~insert~ key
#+BEGIN_SRC emacs-lisp
(keymap-global-set "<insert>" nil)
#+END_SRC
*** Elisp/Eval bindings
-:PROPERTIES:
-:ID: 05c8bf80-e35f-49bc-97b0-b6caccb63ab6
-:END:
**** Eval Region
-:PROPERTIES:
-:ID: c19da360-569b-4ac9-bd24-bd7cfa665d6c
-:END:
Some old Emacs-like editor (Edwin?) used this binding, so I put it in here. Less used than the =C-M-x= =eval-defun= binding, but occasionally nice to have.
#+BEGIN_SRC emacs-lisp
(keymap-global-set "C-M-z" 'eval-region)
#+END_SRC
*** *NIX
-:PROPERTIES:
-:ID: ecfe90a8-05d6-468b-b82a-5558c4a226c1
-:END:
These defuns are here so that I can use doas/sudo over tramp to edit /local/ files requiring root permissions. Doas for BSD, Sudo for Linux, nothing for Windows.
#+BEGIN_SRC emacs-lisp
(unless (or (equal system-type 'windows-nt)
#+END_SRC
*** Windows
-:PROPERTIES:
-:ID: 857da290-c22e-4e38-a427-714527cf392f
-:END:
If you've ever had the /pleasure/ of using Aveva (*Formerly WonderWare*) version 2020, you'll understand.
#+BEGIN_SRC emacs-lisp
(when (equal system-type 'windows-nt)
#+END_SRC
*** Math
-:PROPERTIES:
-:ID: 69a05305-6b16-4abf-bf9a-b858d9a7e642
-:END:
General Math defuns, often used in later defuns.
**** Exponentiation
-:PROPERTIES:
-:ID: 14d9a8c0-2984-4d53-b933-01366b286208
-:END:
I'm tired of writing out ='expt=, and I want to use the same notation every other programming language does.
#+BEGIN_SRC emacs-lisp
(defalias '^ 'expt)
#+END_SRC
**** Square, Cube, and Inv
-:PROPERTIES:
-:ID: 871f50e4-447e-4da0-b86f-ec253c7d48cf
-:END:
Define square, cube, and inv for brevity of common usages.
#+BEGIN_SRC emacs-lisp
(defun square (x)
#+END_SRC
*** Unit Conversions
-:PROPERTIES:
-:ID: d756d65e-aca5-4718-af09-aaecbbd62f99
-:END:
The rest of the world decided to self-castrate because some French guys told them things Definitely Made More Sense if everything was divisible by 10. I'm convinced the average Frenchman simply couldn't grasp fractions, and that's why he came up with this crap. What's 1/3 of a meter? What's 1/3 of a yard? And 1/3 of a foot? How likely are you to need to divide a measurement by 3 when you're building something? Maybe the [[https://dozenal.org/][Dozenal]] people were right all along. Anyway, I'm now forced to convert into proper units daily because of this grave error.
#+BEGIN_SRC emacs-lisp
#+END_SRC
*** Electrical
-:PROPERTIES:
-:ID: 8c0d72bc-b8ba-4f9f-be49-876bd624c2ae
-:END:
These defuns are all about electronics. Effective impedance, amps to volts, and back again.
#+BEGIN_SRC emacs-lisp
(defun eff-imp (r1 &optional r2)
#+END_SRC
*** PLC
-:PROPERTIES:
-:ID: 850536ef-64b6-44d6-9b64-61d2a4ed050a
-:END:
The nitty-gritty. These defuns build on the previous ones to help me do various calculations related to analog signals and how they interact with [[https://en.wikipedia.org/wiki/Programmable_logic_controller][PLCs]], also called PACs. Counts, volts, amps, bit-resolutions, and relating them to each other.
#+BEGIN_SRC emacs-lisp
(defun max-counts (resolution)
#+END_SRC
*** Refrigeration
-:PROPERTIES:
-:ID: 18225f24-139e-4707-8935-03a6cf48290a
-:END:
More nitty-gritty. These are for calculating specific refrigeration-related things. Somewhat specialized.
#+BEGIN_SRC emacs-lisp
(defun cfm-circ (fpm radius)
#+END_SRC
** org configuration
-:PROPERTIES:
-:ID: 3ace6f84-14f7-4d64-a78c-b46b4a1ca66c
-:END:
My (now-sprawling) org configuration
*** Startup options
-:PROPERTIES:
-:ID: 86db2539-2da8-49a5-852d-19f99dd81393
-:END:
Start folded, and show stars as indentation.
#+BEGIN_SRC emacs-lisp
(setq org-startup-folded t
#+END_SRC
*** Basics
-:PROPERTIES:
-:ID: d7161d70-f42c-43da-b454-974604d2b005
-:END:
Don't split my line, just make a new one, follow links with return, export tables as csvs, set the default export backends, and use an absolute path for other links (while shortening home to ~).
#+BEGIN_SRC emacs-lisp
(setq org-M-RET-may-split-line nil
#+END_SRC
*** TO-DO options
-:PROPERTIES:
-:ID: 28154d92-b384-4d0e-bf9d-35bd9de59f58
-:END:
Select with single key, enforce sub-tasks, only change the color of the keyword.
#+BEGIN_SRC emacs-lisp
(setq org-use-fast-todo-selection 'expert
#+END_SRC
*** Navigation
-:PROPERTIES:
-:ID: 7c85b584-936b-4763-90c0-3de8fabc36ae
-:END:
Make the =C-c C-j= binding more useful
#+BEGIN_SRC emacs-lisp
(setq org-goto-interface 'outline-path-completion
#+END_SRC
*** Special keys & subtree yanking
-:PROPERTIES:
-:ID: 396b69c0-7078-420a-9be3-5bf478a87584
-:END:
Org special keys - do logical things with =C-a/e/k=, and adjust subtree level when yanking.
#+BEGIN_SRC emacs-lisp
(setq org-special-ctrl-a/e t
#+END_SRC
*** File Opening
-:PROPERTIES:
-:ID: e7426184-8474-45d8-b0c4-a4a2ed99101d
-:END:
Don't open links in another window, just use the current one.
#+BEGIN_SRC emacs-lisp
(setq org-link-frame-setup '((file . find-file)))
#+END_SRC
*** Directories
-:PROPERTIES:
-:ID: 5fbbe7e3-8da5-453e-b7a3-45eee036d662
-:END:
Tell org where everything is
#+BEGIN_SRC emacs-lisp
(setq org-directory "~/org"
org-journal-file "~/org/journal.org")
#+END_SRC
*** Refile
-:PROPERTIES:
-:ID: 4cca59d2-f47a-4e9d-8c22-162a81aac629
-:END:
Let me refile anywhere, use outline paths, confirm when creating parent nodes.
#+BEGIN_SRC emacs-lisp
(setq org-refile-targets '((nil :maxlevel . 9)
#+END_SRC
*** Keywords
-:PROPERTIES:
-:ID: 8505da9e-71ae-42da-a5ff-8e80ca96dd30
-:END:
Set up some more todo keywords
#+BEGIN_SRC emacs-lisp
(setq org-todo-keywords '((sequence "TODO(t)"
#+END_SRC
*** Tag Filtering
-:PROPERTIES:
-:ID: 1aa94af1-7a65-4ad1-8ac5-dd919252b4ab
-:END:
Add some much-used tags with shortcuts.
#+BEGIN_SRC emacs-lisp
(setq org-tag-alist '((:startgroup . nil)
#+END_SRC
*** Agenda
-:PROPERTIES:
-:ID: f9839acc-459b-42be-983d-3b3609d470cf
-:END:
**** General options
-:PROPERTIES:
-:ID: a0e6d683-63ac-4cfe-b2fc-4eb0d096f704
-:END:
Go back to previous view on quit, always start on current day, warn me for 30 days of a deadline, use the current window for the agenda, and don't show tags, but show full heirarchy.
#+BEGIN_SRC emacs-lisp
(setq org-agenda-restore-windows-after-quit t
#+END_SRC
**** Custom View
-:PROPERTIES:
-:ID: 12d59694-3e27-4e53-8ba3-7c341a0d1c2d
-:END:
Set up the agenda view. Access it with ~C-c a SPC~, [[id:3281906e-1f44-4abb-9f9d-0a0a39221752][or ~F2~]].
#+BEGIN_SRC emacs-lisp
(setq org-agenda-custom-commands '((" " "Agenda"
#+END_SRC
**** Custom Agenda on Single key
-:PROPERTIES:
-:ID: c921d7e6-63ef-4a89-851a-0f3a122e9fa0
-:END:
Stolen from [[https://emacs.stackexchange.com/questions/864/how-to-bind-a-key-to-a-specific-agenda-command-list-in-org-mode][Stack Exchange]]
#+BEGIN_SRC emacs-lisp
(defun re/org-agenda-show-custom (&optional arg)
#+END_SRC
**** Column View
-:PROPERTIES:
-:ID: b30e7269-c0ba-4014-9fb9-e03e6734a4db
-:END:
Set up the format for column view.
#+BEGIN_SRC emacs-lisp
(setq org-columns-default-format "%50ITEM(Task) %10CLOCKSUM %16TIMESTAMP_IA"
#+END_SRC
**** Clock settings
-:PROPERTIES:
-:ID: 31a4e74d-dab5-43dc-9953-b3beb6db9150
-:END:
Resume clocking when emacs restarts, save&load running clock and history on exit/startup, resume last task on clock-in if clock is open, resume active clock without prompt, include current clocking task in reports, and make the clocktable look nice.
#+BEGIN_SRC emacs-lisp
(org-clock-persistence-insinuate)
#+END_SRC
*** Capture Templates
-:PROPERTIES:
-:ID: ab7c773c-5a03-4c7b-be8a-318f2b3fd0db
-:END:
Capture Templates per my proclivities.
#+BEGIN_SRC emacs-lisp
(setq org-capture-templates '(("n" "Note" entry (file org-default-notes-file)
#+END_SRC
*** Abbreviations & Snippets
-:PROPERTIES:
-:ID: d4d9cdef-583a-4fad-9cb2-17a80e093374
-:END:
**** Abbrev-Mode settings
-:PROPERTIES:
-:ID: ce23e846-972f-46c7-b7a6-b313b4149e79
-:END:
Start up =abbrev-mode= for org
#+BEGIN_SRC emacs-lisp
(add-hook 'org-mode-hook #'abbrev-mode)
#+END_SRC
**** Skeletons
-:PROPERTIES:
-:ID: fffe9361-bae6-4ceb-8a71-5d06e711528d
-:END:
***** General source Block
-:PROPERTIES:
-:ID: f469a595-d370-46b5-8d8e-afab9a816c97
-:END:
#+BEGIN_SRC emacs-lisp
(define-skeleton skel-org-block
"Insert an org source code block"
#+END_SRC
***** Emacs Lisp source Block
-:PROPERTIES:
-:ID: eb47039c-d264-4a61-8da8-7659cbc02b62
-:END:
#+BEGIN_SRC emacs-lisp
(define-skeleton skel-org-block-elisp
"Insert an org emacs lisp block"
"#+END_SRC\n")
#+END_SRC
***** Facility properties block
-:PROPERTIES:
-:ID: 30630b60-66ca-40ed-a30b-9a95a2be7c70
-:END:
#+BEGIN_SRC emacs-lisp
(define-skeleton skel-facility-properties
"Insert the org title and filetags for a new facility."
#+END_SRC
***** Person properties block
-:PROPERTIES:
-:ID: 0e57ecbf-b0f5-4f7c-ad1d-d3ef69cb7581
-:END:
#+BEGIN_SRC emacs-lisp
(define-skeleton skel-person-properties
"Insert the org title and filetags for a person."
#+END_SRC
***** Workorder properties block
-:PROPERTIES:
-:ID: a0062c3f-caf0-4de4-9d95-0dffc04eba31
-:END:
#+BEGIN_SRC emacs-lisp
(define-skeleton skel-workorder-properties
"Insert the org title and filetags for a workorder"
#+END_SRC
**** Bind the snippets (in the =abbrev-file-name= file)
-:PROPERTIES:
-:ID: 1e9362ab-d7da-4d87-bef4-9a6c39530832
-:END:
#+BEGIN_SRC emacs-lisp :tangle ./abbrev_defs
;;-*-coding: utf-8;-*-
(define-abbrev-table 'org-mode-abbrev-table
#+END_SRC
*** Auto-archive
-:PROPERTIES:
-:ID: f1e0b6cf-023f-44e3-a489-15fa04208cd3
-:END:
A function to automatically archive *DONE* items in an org file. I sometimes use this as an after-save-hook header declaration as such:
#+BEGIN_SRC emacs-lisp :tangle no
-*- after-save-hook: (re/org-auto-archive) -*-
#+END_SRC
*** Auto-Generate IDs
-:PROPERTIES:
-:ID: f2660fb6-f995-4b5b-a01c-6bf8b5d9c894
-:END:
**** On Capture
-:PROPERTIES:
-:ID: b40f11e3-8569-4fcd-b083-f1b682f23dc1
-:END:
Generate an ID when I capture someting, and when I try to link to it.
#+BEGIN_SRC emacs-lisp
(setq org-id-link-to-org-use-id t)
#+END_SRC
**** Existing File
-:PROPERTIES:
-:ID: 4120cfb4-59d5-441d-abaa-b49f847f5b90
-:END:
Automatically generate unique IDs if not already created. Stolen from [[https://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode][Stack Overflow]]
#+BEGIN_SRC emacs-lisp
(defun re/org-auto-generate-ids-in-file ()
#+END_SRC
*** Tangling
-:PROPERTIES:
-:ID: f0c4710a-0172-41bc-9744-4fd48872d4a2
-:END:
**** Settings
-:PROPERTIES:
-:ID: 3d8f6700-07a2-4e1e-b3c7-7d77afdcf85c
-:END:
Don't make a new window for source-code edits, and keep indentation consistent.
#+BEGIN_SRC emacs-lisp
(setq org-src-window-setup 'current-window
#+END_SRC
**** Auto-tangle init.org
-:PROPERTIES:
-:ID: cd914118-d6e7-485d-b27e-3172f3b77af9
-:END:
Make a function to tangle this file, and run it on save.
#+BEGIN_SRC emacs-lisp
(defun re/tangle-init ()
#+END_SRC
*** Bindings
-:PROPERTIES:
-:ID: adf21035-f2f1-443b-a599-4ce4f282a2ff
-:END:
**** Global
:PROPERTIES:
:ID: 3281906e-1f44-4abb-9f9d-0a0a39221752
#+END_SRC
**** Mode-Specific
-:PROPERTIES:
-:ID: 99906320-74b0-4414-8d87-1ce1ddddad97
-:END:
Give me logical in/out-denting on the easier binding, since I use that more often.
#+BEGIN_SRC emacs-lisp
(add-hook 'org-mode-hook
#+END_SRC
** Dired configuration
-:PROPERTIES:
-:ID: 245c157b-036f-4489-b221-193691a7f94b
-:END:
Make dired use the same switches I prefer for =ls=, give me a simpler listing, and default to using its current buffer for visiting a file, rather than creating a new one.
#+BEGIN_SRC emacs-lisp
(setq dired-listing-switches "-al")
:END:
Here are the various customizations I have for eshell.
*** Binding to start eshell
-:PROPERTIES:
-:ID: 9178eac2-5f69-4574-ae47-b491374f643f
-:END:
#+BEGIN_SRC emacs-lisp
(keymap-global-set "C-c s" 'eshell)
#+END_SRC
*** Make it play nice with corfu
-:PROPERTIES:
-:ID: dc7f2345-2ee3-4883-90ff-b0a8c25c9422
-:END:
-
#+BEGIN_SRC emacs-lisp
(add-hook 'eshell-mode-hook (lambda ()
;; (setq-local corfu-auto nil)
#+END_SRC
*** Send on Close-Paren
-:PROPERTIES:
-:ID: 325c01c5-b877-4281-adff-ea956bdb5f2c
-:END:
I wanted something like what the Genera environment has, where putting in a final close-paren will send the command, without having to hit enter. See [[id:325c01c5-b877-4281-adff-ea956bdb5f2c][Send on Close-Paren]].
#+BEGIN_SRC emacs-lisp
#+END_SRC
*** Quit or delete-char
-:PROPERTIES:
-:ID: ed19265d-4b5c-426b-8c74-cf36939a8b8f
-:END:
I want =C-d= to end the shell if it is on an empty line, otherwise act normally.
#+BEGIN_SRC emacs-lisp
#+END_SRC
*** Bind the defuns
-:PROPERTIES:
-:ID: eac8b87a-0ca9-4d0f-8cd4-1d1538ec16d0
-:END:
I have only been able to get these to work when they are within an add-hook lambda.
#+BEGIN_SRC emacs-lisp
:END:
I wanted something more like a standard lisp REPL in emacs. Found =ielm=.
*** Send on Close-Paren
-:PROPERTIES:
-:ID: 664ba0e7-0826-4868-9480-e1338a6e9f63
-:END:
I wanted something like what the Genera environment has, where putting in a final close-paren will send the command, without having to hit enter. See [[id:325c01c5-b877-4281-adff-ea956bdb5f2c][Send on Close-Paren]].
#+BEGIN_SRC emacs-lisp
(re/send-on-close-paren 'ielm-send-input))
#+END_SRC
*** Persistent command history
-:PROPERTIES:
-:ID: 19726597-2a2e-4059-9447-d7e90696fe08
-:END:
**** Read History
-:PROPERTIES:
-:ID: 6db9d990-00e7-44ec-a83c-b2999fa8db73
-:END:
#+BEGIN_SRC emacs-lisp
(defun re/ielm-init-history ()
"Stolen from https://n16f.net/blog/making-ielm-more-comfortable."
(add-hook 'ielm-mode-hook 're/ielm-init-history)
#+END_SRC
**** Write History
-:PROPERTIES:
-:ID: f7f1df1f-9531-4ef6-b66f-dc0d46295864
-:END:
#+BEGIN_SRC emacs-lisp
(defun re/ielm-write-history (&rest _args)
"Stolen from https://n16f.net/blog/making-ielm-more-comfortable."
(advice-add 'ielm-send-input :after 're/ielm-write-history)
#+END_SRC
*** Bindings
-:PROPERTIES:
-:ID: 68c34ab5-7149-49f5-91e8-fcea22d98fcd
-:END:
~C-l~ to clear buffer, send on close paren.
#+BEGIN_SRC emacs-lisp
(keymap-global-set "C-c i" 'ielm)
(keymap-set inferior-emacs-lisp-mode-map ")" 're/ielm-send-on-close-paren)))
#+END_SRC
** Customize system
-:PROPERTIES:
-:ID: 2fb88065-0c84-4b55-8c5a-59d78a15b134
-:END:
I do not use the customize system. I don't want to see it if I don't have to.
#+BEGIN_SRC emacs-lisp
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
#+END_SRC
** Footer
-:PROPERTIES:
-:ID: 812ba715-1cfe-4f36-baac-71936332b474
-:END:
-
#+BEGIN_SRC emacs-lisp
;;; hic terminatur init.el
#+END_SRC