#+END_SRC
** Basic UI preferences
-I want no menus, no tool-bars, left-side scroll-bars, no blinking cursor, no messages when starting up, and to make resizing work properly. I just want the scratch buffer with a report on =emacs-init-time=.
+I want no menus, no tool-bars, no blinking cursor, no messages when starting up, and to make resizing work properly. 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)
(tool-bar-mode -1)
*** visual-fill-column
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
(use-package visual-fill-column
:ensure t
*** magit
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
(use-package magit
:ensure t
*** openwith
I need to open binary files with their own editor. Disgusting.
-
#+BEGIN_SRC emacs-lisp
(use-package openwith
:ensure t
This section has '/base/' emacs customization. All the general stuff.
*** Defaults
I want these things every time, or at least setting them this way worked when a regular =setq= didn't.
-
#+BEGIN_SRC emacs-lisp
(setq-default indicate-empty-lines t
fill-column 80
cursor-in-non-selected-windows 'hollow)
#+END_SRC
*** Help
-Set up apropos to be more useful
+Set up apropos to be more useful.
#+BEGIN_SRC emacs-lisp
(setq apropos-do-all t)
#+END_SRC
*** UTF-8
-Force emacs to use UTF-8 so I avoid prompts on save
+Force emacs to use UTF-8 so I avoid prompts on save.
#+BEGIN_SRC emacs-lisp
(set-language-environment 'utf-8)
(set-default-coding-systems 'utf-8)
*** Minibuffer interaction
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
(setq ring-bell-function 'ignore
use-short-answers t
*** Buffer interaction
**** General
+***** midnight-mode
Close unused buffers after 3 days.
#+BEGIN_SRC emacs-lisp
(midnight-mode t)
#+END_SRC
+***** delete-selection-mode
Overwrite selection when active, like every other editor since Sam.
#+BEGIN_SRC emacs-lisp
(delete-selection-mode t)
#+END_SRC
-Don't disable any functions.
+***** Don't disable any functions.
#+BEGIN_SRC emacs-lisp
(setq disabled-command-function nil)
#+END_SRC
+***** Inter-program kill-ring
Save pastes from elsewhere into the kill-ring, and don't ask me about killing processes when I kill a buffer.
#+BEGIN_SRC emacs-lisp
(setq save-interprogram-paste-before-kill t
** Defuns and Bindings
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
Most of these are to re-create something from vim/readline/sam/acme. Some are just helper functions or wrappers.
-
**** Visiting Files
Bind ~find-file-at-point~ and ~bookmark-jump-other-window~.
#+BEGIN_SRC emacs-lisp
**** Killing
***** Kill Whole Line
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
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, C-u, and C-h
=C-w= is very much engrained for killing back one word, as is =C-u= for killing back to the beginning of the line, and =C-h= for one character back. [[http://unix-kb.cat-v.org/][These have been standard bindings since TENEX...]]
****** =C-w=
I didn't want to re-bind =C-w= away from =kill-region=, so I made it do both.
-
#+BEGIN_SRC emacs-lisp
(defun re/kill-bword-or-region ()
"Kill region if active, otherwise kill back one word."
****** =C-u=
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
(defun re/backward-kill-line ()
"Kill back to beginning of line from point."
#+END_SRC
****** =C-h=
-We already have =F1= for help. Use this setup instead of ~key-translate~ because that doesn't work whun running the daemon.
+We already have =F1= for help. Use this setup instead of ~key-translate~ because that doesn't work when running the daemon.
#+BEGIN_SRC emacs-lisp
(keymap-set key-translation-map "C-h" "<DEL>")
#+END_SRC
(region-end)))
(deactivate-mark))
(call-interactively 'isearch-backward))
-
-
#+END_SRC
***** Bindings
: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. This is a general command, used by [[id:325c01c5-b877-4281-adff-ea956bdb5f2c][Eshell]], [[id:664ba0e7-0826-4868-9480-e1338a6e9f63][Ielm]], and
+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. This is a general command, used by [[id:325c01c5-b877-4281-adff-ea956bdb5f2c][Eshell]] and [[id:664ba0e7-0826-4868-9480-e1338a6e9f63][Ielm]].
#+BEGIN_SRC emacs-lisp
(defun re/send-on-close-paren (executor)
"Generalizes sending an execute on close paren.
#+BEGIN_SRC emacs-lisp
(defalias '^ 'expt)
#+END_SRC
+
**** Square, Cube, and Inv
Define square, cube, and inv for brevity of common usages.
#+BEGIN_SRC emacs-lisp
*** Unit Conversions
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
(defun mm->in (mm)
"Convert milimeters to inches."
*** Electrical
These defuns are all about electronics. Effective impedance, amps to volts, and back again.
+**** Effective-impedance
#+BEGIN_SRC emacs-lisp
(defun eff-imp (r1 &optional r2)
"Calculate the effective input impedance, given two resistances.
(if (eq nil r2)
r1
(inv (+ (inv r1) (inv r2)))))
+#+END_SRC
+**** Amps to volts
+#+BEGIN_SRC emacs-lisp
(defun amps->volts (amps r1 &optional r2)
"Calculate the voltage, given amperage and impedance.
Multiplies the amperage by the effective impedance calculated
with `eff-imp'."
(* amps (eff-imp r1 r2)))
+#+END_SRC
+**** Volts to amps
+#+BEGIN_SRC emacs-lisp
(defun volts->amps (volts r1 &optional r2)
"Calculate the amperage, given voltage and impedance.
Divides the voltage by the effective impedance calculated with
*** PLC
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.
+**** Max counts
#+BEGIN_SRC emacs-lisp
(defun max-counts (resolution)
"Calculate the max count for a PLC analog, given card's bit-resolution."
(- (^ 2 resolution) 1))
+#+END_SRC
+**** Volts to counts
+#+BEGIN_SRC emacs-lisp
(defun volts->counts (vmax vin resolution)
"Convert a voltage signal to a PLC count.
Calculates a ratio of vin/vmax, then scales by `max-counts'."
(* (/ (float vin) vmax) (max-counts resolution)))
+#+END_SRC
+**** Counts to volts
+#+BEGIN_SRC emacs-lisp
(defun counts->volts (vmax cin resolution)
"Convert a PLC count to a voltage.
Calculates a ratio of cin/`max-counts', then multiplies by vmax."
(* (/ (float cin) (max-counts resolution)) vmax))
+#+END_SRC
+**** Amps to counts
+#+BEGIN_SRC emacs-lisp
(defun amps->counts (vmax amps resolution r1 &optional r2)
"Convert a current signal to PLC Counts.
Converts the amperage to a voltage using `amps->volts' (with r1
and optional r2), then applies `volts->counts' to the resulting
voltage, vmax, and resolution."
(volts->counts vmax (amps->volts amps r1 r2) resolution))
+#+END_SRC
+**** Count range
+#+BEGIN_SRC emacs-lisp
(defun count-range (upper lower vmax resolution &optional r1 r2)
"Given an upper and lower signal, return the list of upper and lower PLC counts.
With a current signal, use r1 and maybe r2 to
(volts->counts vmax lower resolution))
(list (amps->counts vmax upper resolution r1 r2)
(amps->counts vmax lower resolution r1 r2))))
+#+END_SRC
+**** Scaling
+#+BEGIN_SRC emacs-lisp
(defun divisor (raw-max raw-min scaled-max scaled-min)
"Calculate 1/slope given PLC Max/Min and Eng. Max/Min."
(/ (float (- raw-max raw-min)) (- scaled-max scaled-min)))
*** Refrigeration
More nitty-gritty. These are for calculating specific refrigeration-related things. Somewhat specialized.
+**** CFM
#+BEGIN_SRC emacs-lisp
(defun cfm-circ (fpm radius)
"Calculate the CFM of a circular duct.
"Calculate the CFM of a rectangular duct.
Inputs are feet/minute, width (in) and height (in)."
(list (* fpm (/ width 12.0) (/ height 12.0))))
+#+END_SRC
-(defun gn-water-per-lb (temp humidity)
+**** Saturated Water Pressure
+#+BEGIN_SRC emacs-lisp
+(defun sat-water-press (temp)
+ "Calculate the saturated water pressure at a temp (F)."
+ (+ .0182795
+ (* temp .001029904)
+ (* (square temp) 0.00002579408)
+ (* (cube temp) (* 2.400493 (^ 10 -7)))
+ (* (^ temp 4) (* 8.100939 (^ 10 -10)))
+ (* (^ temp 5) (* 3.256805 (^ 10 -11)))
+ (* (^ temp 6) (* -1.001922 (^ 10 -13)))
+ (* (^ temp 7) (* 2.44161 (^ 10 -16)))))
+#+END_SRC
+
+**** Humidity Ratio
+#+BEGIN_SRC emacs-lisp
+(defun hum-ratio (humidity swp)
+ "Calulate the humidity ratio.
+Takes humidity in %RH, and a Saturated Water Pressure."
+ (let ((hum-press (* (/ humidity 100.0) swp)))
+ (/ (* hum-press 0.62198) (- 14.7 hum-press))))
+#+END_SRC
+
+**** Grains of water per lb of air
+#+BEGIN_SRC emacs-lisp
+(defun gn-water-per-lb (humidity temp)
"Calculate the grains of water per lb of air.
-Inputs are temp (F) and humidity (%). Returns a list of
-Saturated Water Pressure, Humidity Ratio, and Grains of water per
-lb of air."
- (let* ((sat-water-press (+ .0182795
- (* temp .001029904)
- (* (square temp) 0.00002579408)
- (* (cube temp) (* 2.400493 (^ 10 -7)))
- (* (^ temp 4) (* 8.100939 (^ 10 -10)))
- (* (^ temp 5) (* 3.256805 (^ 10 -11)))
- (* (^ temp 6) (* -1.001922 (^ 10 -13)))
- (* (^ temp 7) (* 2.44161 (^ 10 -16)))))
- (hum-press (* (/ humidity 100.0) sat-water-press))
- (hum-ratio (/ (* hum-press 0.62198) (- 14.7 hum-press)))
- (gns-water-lb-air (* hum-ratio 7000)))
- (list sat-water-press hum-ratio gns-water-lb-air)))
+Takes humidity in %RH, and temp in F."
+ (* 7000 (hum-ratio humidity (sat-water-press temp))))
#+END_SRC
** org configuration
#+END_SRC
*** Navigation
-Make the =C-c C-j= binding more useful
+Make the =C-c C-j= binding more useful.
#+BEGIN_SRC emacs-lisp
(setq org-goto-interface 'outline-path-completion
org-outline-path-complete-in-steps nil
#+BEGIN_SRC emacs-lisp
(setq org-link-frame-setup '((file . find-file)))
#+END_SRC
+
*** Directories
Tell org where everything is
#+BEGIN_SRC emacs-lisp
org-default-notes-file "~/org/refile.org"
org-journal-file "~/org/journal.org")
#+END_SRC
+
*** Refile
Let me refile anywhere, use outline paths, confirm when creating parent nodes.
#+BEGIN_SRC emacs-lisp
_ - \n
"#+END_SRC\n")
#+END_SRC
+
***** Facility properties block
#+BEGIN_SRC emacs-lisp
(define-skeleton skel-facility-properties
(org-map-entries 'org-id-get-create))
#+END_SRC
-Run this on save of any org-mode file
+Don't run this on save of any org-mode file like we used to. (no longer tangling this block).
#+BEGIN_SRC emacs-lisp :tangle no
(add-hook 'org-mode-hook
(lambda ()
*** Send on Close-Paren
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
(defun re/eshell-send-on-close-paren ()
"Makes eshell act somewhat like genera.
*** Quit or delete-char
I want =C-d= to end the shell if it is on an empty line, otherwise act normally.
-
#+BEGIN_SRC emacs-lisp
(defun eshell-quit-or-delete-char (arg)
"Delete char if at one, quit eshell if on empty prompt.
*** Bind the defuns
I have only been able to get these to work when they are within an add-hook lambda.
-
#+BEGIN_SRC emacs-lisp
(add-hook 'eshell-mode-hook
(lambda ()
(keymap-set eshell-mode-map ")" 're/eshell-send-on-close-paren)
(keymap-set eshell-mode-map "C-d" 'eshell-quit-or-delete-char)))
#+END_SRC
+
** ielm configuration
:PROPERTIES:
:ID: e7a7b861-8f63-4036-9f68-59fb954a7561
I wanted something more like a standard lisp REPL in emacs. Found =ielm=.
*** Send on Close-Paren
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
(defun re/ielm-send-on-close-paren ()
"Makes ielm act somewhat like genera.
(interactive)
(re/send-on-close-paren 'ielm-send-input))
#+END_SRC
+
*** Persistent command history
**** Read History
#+BEGIN_SRC emacs-lisp
(add-hook 'ielm-mode-hook 're/ielm-init-history)
#+END_SRC
+
**** Write History
#+BEGIN_SRC emacs-lisp
(defun re/ielm-write-history (&rest _args)
(advice-add 'ielm-send-input :after 're/ielm-write-history)
#+END_SRC
+
*** Bindings
~C-l~ to clear buffer, send on close paren.
#+BEGIN_SRC emacs-lisp
(keymap-set inferior-emacs-lisp-mode-map "C-l" 'comint-clear-buffer)
(keymap-set inferior-emacs-lisp-mode-map ")" 're/ielm-send-on-close-paren)))
#+END_SRC
+
** Customize system
I do not use the customize system. I don't want to see it if I don't have to.
#+BEGIN_SRC emacs-lisp