;; Code:
#+END_SRC
-** Basic UI preferences
-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~.
+** Startup options
+I want 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
-(menu-bar-mode -1)
-(tool-bar-mode -1)
-(blink-cursor-mode -1)
-
(setq inhibit-startup-screen t
inhibit-startup-buffer-menu t
server-client-instructions nil
#+END_SRC
*** 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.
+A godsend. Finally, I can have visual-line-mode without having to read lines that are 1920 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
cursor-type 'bar
cursor-in-non-selected-windows 'hollow)
#+END_SRC
+
+*** Visuals
+**** De-Clutter
+No menu-bar, no tool-bar, no blinking cursor
+#+BEGIN_SRC emacs-lisp
+(menu-bar-mode -1)
+(tool-bar-mode -1)
+(blink-cursor-mode -1)
+#+END_SRC
+
+**** Scroll Bars
+Put my scroll bars where I like them.
+#+BEGIN_SRC emacs-lisp
+(set-scroll-bar-mode 'left)
+#+END_SRC
+
+**** Prettify Symbols
+I want nice symbols to look at
+#+BEGIN_SRC emacs-lisp
+(setq prettify-symbols-alist '(("lambda" . 955)
+ ("delta" . 120517)
+ ("epsilon" . 120518)
+ ("->" . 8594)
+ ("<=" . 8804)
+ (">=" . 8805)))
+(global-prettify-symbols-mode t)
+#+END_SRC
+
+**** Visual Line Mode indicators
+Show arrows when a line wraps
+#+BEGIN_SRC emacs-lisp
+(setq-default visual-line-fringe-indicators '(left-curly-arrow right-curly-arrow))
+#+END_SRC
+
+**** Parens
+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.
+#+BEGIN_SRC emacs-lisp
+(setq show-paren-delay 0
+ show-paren-style 'expression)
+#+END_SRC
+
+Make the paren "highlight" the same color as the background, with no overwrite of foreground color, and add underline.
+#+BEGIN_SRC emacs-lisp
+(set-face-attribute 'show-paren-match nil
+ :foreground 'unspecified
+ :background 'unspecified
+ :underline t)
+#+END_SRC
+
+**** Modeline
+Funny name for the frame
+#+BEGIN_SRC emacs-lisp
+(setq frame-title-format "Poor Man's LispM")
+#+END_SRC
+
+Show me column number and filesize
+#+BEGIN_SRC emacs-lisp
+(column-number-mode t)
+(size-indication-mode t)
+#+END_SRC
+
*** Help
Set up apropos to be more useful.
#+BEGIN_SRC emacs-lisp
**** 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
- confirm-kill-processes nil)
+(setq save-interprogram-paste-before-kill t)
+#+END_SRC
+
+**** Kill Processes
+Don't ask for confirmation when I kill a process by killing the buffer
+#+BEGIN_SRC emacs-lisp
+(setq confirm-kill-processes nil)
#+END_SRC
**** Maus
(keymap-global-set "C-c r" 'recentf-open-files)
#+END_SRC
-*** Buffer looks
-**** Prettify Symbols
-I want nice symbols to look at
-#+BEGIN_SRC emacs-lisp
-(setq prettify-symbols-alist '(("lambda" . 955)
- ("delta" . 120517)
- ("epsilon" . 120518)
- ("->" . 8594)
- ("<=" . 8804)
- (">=" . 8805)))
-(global-prettify-symbols-mode t)
-#+END_SRC
-
-**** Visual Line Mode indicators
-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
-Put my scroll bars where I like them.
-#+BEGIN_SRC emacs-lisp
-(set-scroll-bar-mode 'left)
-#+END_SRC
-
-*** Parens
-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.
-#+BEGIN_SRC emacs-lisp
-(setq show-paren-delay 0
- show-paren-style 'expression)
-#+END_SRC
-
-Make the paren "highlight" the same color as the background, with no overwrite of foreground color, and add underline.
-#+BEGIN_SRC emacs-lisp
-(set-face-attribute 'show-paren-match nil
- :foreground 'unspecified
- :background 'unspecified
- :underline t)
-#+END_SRC
-
-*** Modeline
-Funny name for the frame
-#+BEGIN_SRC emacs-lisp
-(setq frame-title-format "Poor Man's LispM")
-#+END_SRC
-
-Show me column number and filesize
-#+BEGIN_SRC emacs-lisp
-(column-number-mode t)
-(size-indication-mode t)
-#+END_SRC
-
*** C-Style
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
#+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=
+=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 ()
(keymap-global-set "C-w" 're/kill-bword-or-region)
#+END_SRC
-****** =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=.
+****** C-u
+There is no pre-made function to kill backward to the beginning of line from point, so I made a lambda 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."
- (interactive)
- (kill-line 0))
-
-(keymap-global-set "C-u" 're/backward-kill-line)
+(keymap-global-set "C-u" '(lambda () (interactive) (kill-line 0)))
#+END_SRC
Since =C-u= is =universal-argument=, I put that functionality on =M-'=.
(keymap-global-set "M-'" 'universal-argument)
#+END_SRC
-****** =C-h=
+****** C-h
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>")
(keymap-global-set "<end>" 'end-of-buffer)
#+END_SRC
-***** Beginning of line
-****** ~smart-beginning-of-line~
-I have the infamous =smart-beginning-of-line= command here.
+***** Beginning/End of line
+****** smart-beginning-of-line to play nice with ~visual-line-mode~ while ~org-mode~ is active.
+Modified from BrettWitty's github repo. 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-line ()
- "Move point to first non-whitespace character or beginning-of-line.
-If point was already at that position, move point to beginning of
-line. Stolen from BrettWitty's dotemacs github repo."
+ "Move point to first non-whitespace character or `beginning-of-visual-line'.
+If point was already at that position, call `back-to-indentation'.
+Called a third time, move point to `beginning-of-line'.
+If in org-mode, call `org-beginning-of-line' first."
(interactive "^")
(let ((oldpos (point)))
- (back-to-indentation)
+ (if (equal major-mode 'org-mode)
+ (org-beginning-of-line)
+ (progn
+ (beginning-of-visual-line 1)
+ (skip-syntax-forward " " (line-end-position))
+ (backward-prefix-chars)))
(and (= oldpos (point))
- (beginning-of-line))))
+ (let ((newpos (point)))
+ (back-to-indentation)
+ (and (= newpos (point))
+ (beginning-of-line))))))
#+END_SRC
-****** Play nice with ~visual-line-mode~
-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~.
+
+****** smart-end-of-line
+Go to end of visual line, then end of line, unless in org-mode
#+BEGIN_SRC emacs-lisp
-(defun re/smart-beginning-of-visual-line ()
- "Move point to first non-whitespace character or beginning-of-line.
-If point was already at that position, move point to beginning of
-line. Stolen from BrettWitty's dotemacs github repo. Modified to
-work in visual-line-mode. Re-implementing `back-to-indentation'
-as a visual-line respecter."
+(defun re/smart-end-of-line ()
+ "Move point to the end of the visual line. If point was already at that position, call `move-end-of-line'.
+If in org-mode, call `org-end-of-line' first."
(interactive "^")
(let ((oldpos (point)))
- (beginning-of-visual-line 1)
- (skip-syntax-forward " " (line-end-position))
- (backward-prefix-chars)
+ (if (equal major-mode 'org-mode)
+ (org-end-of-line)
+ (end-of-visual-line 1))
(and (= oldpos (point))
- (beginning-of-visual-line))))
+ (move-end-of-line nil))))
+
#+END_SRC
+
****** Re-mappings
-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=.
+Remap ~move-beginning-of-line~ and ~move-end-of-line~, then remap ~beginning-of-visual-line~ and ~end-of-visual-line~ in the ~visual-line-mode-map~.
#+BEGIN_SRC emacs-lisp
(keymap-global-set "<remap> <move-beginning-of-line>" 're/smart-beginning-of-line)
-(add-hook 'visual-line-mode-hook
- (lambda ()
- (keymap-global-set "C-a" 're/smart-beginning-of-visual-line)))
+(keymap-global-set "<remap> <move-end-of-line>" 're/smart-end-of-line)
+
+(keymap-set visual-line-mode-map "C-a" 're/smart-beginning-of-line)
+(keymap-set visual-line-mode-map "C-e" 're/smart-end-of-line)
#+END_SRC
***** Line Numbers on move only
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.
(keymap-global-set "<remap> <upcase-word>" 'upcase-dwim)
#+END_SRC
-*** Elisp/Eval bindings
+*** Elisp/Eval
**** Eval Region
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
(call-interactively ,executor))))
#+END_SRC
-*** *NIX
+*** BSD/Linux
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 (equal system-type 'windows-nt)
buffer-file-name))))))
#+END_SRC
-*** Windows
+*** Work-Related
+**** Windows
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)
(when (file-exists-p xml2) (delete-file xml2)))))
#+END_SRC
-*** Math
+**** Math
General Math defuns, often used in later defuns.
-**** Exponentiation
+***** Exponentiation
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
+***** Square, Cube, and Inv
Macros for square, cube, and inv for brevity of common usages.
#+BEGIN_SRC emacs-lisp
(defmacro square (x)
`(/ 1 (float ,x)))
#+END_SRC
-**** Engineering Notation (kinda)
+***** Engineering Notation (kinda)
A macro to give me /prefix/ Engineering notation.
#+BEGIN_SRC emacs-lisp
(defmacro E (number exponent)
`(* ,number (^ 10 ,exponent)))
#+END_SRC
-*** Unit Conversions
+**** 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.
-**** Length
+***** Length
#+BEGIN_SRC emacs-lisp
(defun mm->in (mm)
"Convert milimeters to inches."
(* in 25.4))
#+END_SRC
-**** Temperature
+***** Temperature
#+BEGIN_SRC emacs-lisp
(defun k->c (tempk)
"Convert degrees Kelvin to degrees Celsius."
(c->k (f->c tempf)))
#+END_SRC
-*** Electrical
+**** Electrical
These defuns are all about electronics. Effective impedance, amps to volts, and back again.
-**** Effective-impedance
+***** Effective-impedance
#+BEGIN_SRC emacs-lisp
(defun eff-imp (r1 &optional r2)
"Calculate the effective input impedance, given two resistances.
(inv (+ (inv r1) (inv r2)))))
#+END_SRC
-**** Amps to volts
+***** Amps to volts
#+BEGIN_SRC emacs-lisp
(defun amps->volts (amps r1 &optional r2)
"Calculate the voltage, given amperage and impedance.
(* amps (eff-imp r1 r2)))
#+END_SRC
-**** Volts to amps
+***** Volts to amps
#+BEGIN_SRC emacs-lisp
(defun volts->amps (volts r1 &optional r2)
"Calculate the amperage, given voltage and impedance.
(/ volts (eff-imp r1 r2)))
#+END_SRC
-*** PLC
+**** 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
+***** Max counts
#+BEGIN_SRC emacs-lisp
(defun max-counts (resolution)
"Calculate the max count for a PLC analog, given card's bit-resolution."
(1- (^ 2 resolution)))
#+END_SRC
-**** Volts to counts
+***** Volts to counts
#+BEGIN_SRC emacs-lisp
(defun volts->counts (vmax vin resolution)
"Convert a voltage signal to a PLC count.
(* (/ (float vin) vmax) (max-counts resolution)))
#+END_SRC
-**** Counts to volts
+***** Counts to volts
#+BEGIN_SRC emacs-lisp
(defun counts->volts (vmax cin resolution)
"Convert a PLC count to a voltage.
(* (/ (float cin) (max-counts resolution)) vmax))
#+END_SRC
-**** Amps to counts
+***** Amps to counts
#+BEGIN_SRC emacs-lisp
(defun amps->counts (vmax amps resolution r1 &optional r2)
"Convert a current signal to PLC Counts.
(volts->counts vmax (amps->volts amps r1 r2) resolution))
#+END_SRC
-**** Count range
+***** 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.
(amps->counts vmax lower resolution r1 r2))))
#+END_SRC
-**** Scaling
+***** 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."
(list div os (final analog-input div os)))))
#+END_SRC
-*** Refrigeration
+**** Refrigeration
More nitty-gritty. These are for calculating specific refrigeration-related things. Somewhat specialized.
-**** CFM
+***** CFM
#+BEGIN_SRC emacs-lisp
(defun cfm-circ (fpm radius)
"Calculate the CFM of a circular duct.
(list (* fpm (/ width 12.0) (/ height 12.0))))
#+END_SRC
-**** Saturated Water Pressure
+***** Saturated Water Pressure
#+BEGIN_SRC emacs-lisp
(defun sat-water-press (temp)
"Calculate the saturated water pressure at a temp (F)."
(* (^ temp 7) (E 2.44161 -16))))
#+END_SRC
-**** Humidity Ratio
+***** Humidity Ratio
#+BEGIN_SRC emacs-lisp
(defun hum-ratio (humidity swp)
"Calulate the humidity ratio.
(/ (* hum-press 0.62198) (- 14.7 hum-press))))
#+END_SRC
-**** Grains of water per lb of air
+***** 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.