]> git.earman.xyz Git - emacsinit.git/commitdiff
Buffer switching, some defuns to macros
authorrearman <rearman@r717.net>
Fri, 14 Jun 2024 14:53:42 +0000 (10:53 -0400)
committerrearman <rearman@r717.net>
Fri, 14 Jun 2024 14:53:42 +0000 (10:53 -0400)
config.org
early-init.el

index 8ce6a3cfd3bc6f501aac97ea00dc91fc292c85b5..f30fd981c735623d2f1b440a883b93e6e1364539 100644 (file)
@@ -16,7 +16,7 @@ I believe that all scientific knowledge, and by extension computational knowledg
 * Meta Configuration
 I have changed the meta.  I no longer overwrite the init.el, instead opting to have the init.el tangle this file.
 * Early init
-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 on Windows.
+This file was introduced in Emacs 27.  I use it mainly for speeding up init.  Maybe superfluous, but I do get startup times on the order of /0.015/ seconds on Windows.
 ** The normal header
 There are no GNU Police (yet), but I feel nicer by adding this in.
 #+BEGIN_SRC emacs-lisp :tangle ./early-init.el
@@ -28,33 +28,19 @@ There are no GNU Police (yet), but I feel nicer by adding this in.
 #+END_SRC
 
 ** GC thrashing
-Set the GC threshold to max during startup, then set it back to a value that is somewhat more sane than the default /800kb/.
+Set the GC threshold to max during startup, then set it back to a normal value.  Currently testing what "normal" is - slowly raising from default 800k.
 
 #+BEGIN_SRC emacs-lisp :tangle ./early-init.el
 (setq gc-cons-threshold most-positive-fixnum
       gc-cons-percentage 0.6)
 
-;; (add-hook 'after-init-hook #'(lambda () (setq gc-cons-threshold (* 1024 1024 25)
-;;                                          gc-cons-percentage 0.1)))
+(add-hook 'after-init-hook #'(lambda () (setq gc-cons-threshold (* 800 1000)
+                                         gc-cons-percentage 0.1
+                                         garbage-collection-messages t)))
 #+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=.
-#+BEGIN_SRC emacs-lisp :tangle ./early-init.el
-(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
-      frame-resize-pixelwise t
-      initial-scratch-message (message ";;; Emacs loaded in %s.\n\n" (emacs-init-time)))
-#+END_SRC
-
-** Misc/odd issues
-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.
-
+** Default to home
+Have seen the daemon sometimes set a weird default directory.  Ensure it gets set to home.
 #+BEGIN_SRC emacs-lisp :tangle ./early-init.el
 (setq default-directory "~/")
 #+END_SRC
@@ -76,6 +62,20 @@ Avoid a weird issue on windows where opening emacs via an [[https://www.autohotk
 ;; 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=.
+#+BEGIN_SRC emacs-lisp :tangle ./early-init.el
+(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
+      frame-resize-pixelwise t
+      initial-scratch-message (message ";;; Emacs loaded in %s.\n\n" (emacs-init-time)))
+#+END_SRC
+
 ** Packages
 Load packages first, so there is no question about dependencies later in the file.
 *** Package Repositories
@@ -84,22 +84,6 @@ Non-gnu is in the defaults now, so I only need to add melpa.
 (require 'package)
 (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
 #+END_SRC
-*** Garbage Collector Magic Hack
-Better Performance?  Taken from [[https://rossabaker.com/configs/emacs/#garbage-collection][rossbaker.com]]
-#+BEGIN_SRC emacs-lisp
-(use-package gcmh
-  :ensure t
-  :init
-  (setq gc-cons-threshold most-positive-fixnum)
-  :hook
-  (emacs-startup . gcmh-mode)
-  :custom
-  (gcmh-idle-delay 'auto)
-  (gcmh-verbose t)
-  (gcmh-auto-idle-delay-factor 10)
-  (gcmh-high-cons-threshold (* 4 1024 1024)))
-#+END_SRC
-
 *** Ledger-mode
 Accounting
 #+BEGIN_SRC emacs-lisp
@@ -477,7 +461,7 @@ Use =recycle bin=, DON'T use =AltGr=, and tell emacs where =diff= is.
         w32-recognize-altgr 'nil))
 #+END_SRC
 
-** Defuns and Bindings
+** Defuns, macros, 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.
@@ -721,6 +705,14 @@ I ripped this defun and binding from [[https://github.com/lem-project/lem][lem]]
 
 (keymap-global-set "C-M-o" 're/other-window-or-split-window)
 #+END_SRC
+***** Previous/next buffer
+~C-x <arrow>~ is awkward, so use ~M-n/p~ instead.  Also let me use the mouse's back button.
+#+BEGIN_SRC emacs-lisp
+(keymap-global-set "M-n" 'next-buffer)
+(keymap-global-set "M-p" 'previous-buffer)
+(keymap-global-set "<mouse-4>" 'previous-buffer)
+#+END_SRC
+
 **** Search and Replace
 ***** Search with region
 #+BEGIN_SRC emacs-lisp
@@ -777,15 +769,16 @@ Some old Emacs-like editor (Edwin?) used this binding, so I put it in here.  Les
 :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]] and [[id:664ba0e7-0826-4868-9480-e1338a6e9f63][Ielm]].
+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:314c137f-3674-4194-ae85-8fdb3c2edd32][Eshell]] and [[id:8e0a0ad5-ba71-4a73-a739-4754b37edb7f][Ielm]].
 #+BEGIN_SRC emacs-lisp
-(defun re/send-on-close-paren (executor)
+(defmacro re/send-on-close-paren (executor)
   "Generalizes sending an execute on close paren.
-When a sexp is complete - that is when parens balance as you type - execute it."
-  (interactive)
-  (insert-char ?\))
-  (when (= 0 (car (syntax-ppss)))
-    (call-interactively executor)))
+When a sexp is complete - that is when parens balance as you type - execute it.
+Use this macro as a direct binding"
+  `(lambda ()
+     (insert-char 41)
+     (when (= 0 (car (syntax-ppss)))
+       (call-interactively ,executor))))
 #+END_SRC
 
 *** *NIX
@@ -832,23 +825,33 @@ I'm tired of writing out ='expt=, and I want to use the same notation every othe
 #+END_SRC
 
 **** Square, Cube, and Inv
-Define square, cube, and inv for brevity of common usages.
+Macros for square, cube, and inv for brevity of common usages.
 #+BEGIN_SRC emacs-lisp
-(defun square (x)
+(defmacro square (x)
   "Calculate the square of a value."
-  (^ x 2))
+  `(^ ,x 2))
 
-(defun cube (x)
+(defmacro cube (x)
   "Calculate the cube of a value."
-  (^ x 3))
+  `(^ ,x 3))
 
-(defun inv (x)
+(defmacro inv (x)
   "Calculate the inverse of a value."
-  (/ 1 (float x)))
+  `(/ 1 (float ,x)))
+#+END_SRC
+
+**** Engineering Notation (kinda)
+A macro to give me /prefix/ Engineering notation.
+#+BEGIN_SRC emacs-lisp
+(defmacro E (number exponent)
+  "Pseudo Engineering notation.
+i.e. (E 5 3) == 5E3 == 5000"
+  `(* ,number (^ 10 ,exponent)))
 #+END_SRC
 
 *** 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
 #+BEGIN_SRC emacs-lisp
 (defun mm->in (mm)
   "Convert milimeters to inches."
@@ -857,7 +860,10 @@ The rest of the world decided to self-castrate because some French guys told the
 (defun in->mm (in)
   "Convert inches to milimeters."
   (* in 25.4))
+#+END_SRC
 
+**** Temperature
+#+BEGIN_SRC emacs-lisp
 (defun k->c (tempk)
   "Convert degrees Kelvin to degrees Celsius."
   (- tempk 273.15))
@@ -923,7 +929,7 @@ The nitty-gritty.  These defuns build on the previous ones to help me do various
 #+BEGIN_SRC emacs-lisp
 (defun max-counts (resolution)
   "Calculate the max count for a PLC analog, given card's bit-resolution."
-  (- (^ 2 resolution) 1))
+  (1- (^ 2 resolution)))
 #+END_SRC
 
 **** Volts to counts
@@ -1011,11 +1017,11 @@ Inputs are feet/minute, width (in) and height (in)."
   (+ .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)))))
+     (* (cube temp) (E 2.400493 -7))
+     (* (^ temp 4) (E 8.100939 -10))
+     (* (^ temp 5) (E 3.256805 -11))
+     (* (^ temp 6) (E -1.001922 -13))
+     (* (^ temp 7) (E 2.44161 -16))))
 #+END_SRC
 
 **** Humidity Ratio
@@ -1429,19 +1435,9 @@ Here are the various customizations I have for eshell.
 
 *** Make it play nice with corfu
 #+BEGIN_SRC emacs-lisp
-(add-hook 'eshell-mode-hook (lambda ()
-                              (setq-local corfu-auto nil)
-                              (corfu-mode)))
-#+END_SRC
-
-*** 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.
-Makes a closing paren execute the sexp."
-  (interactive)
-  (re/send-on-close-paren 'eshell-send-input))
+;; (add-hook 'eshell-mode-hook (lambda ()
+;;                               (setq-local corfu-auto nil)
+;;                               (corfu-mode)))
 #+END_SRC
 
 *** Quit or delete-char
@@ -1457,11 +1453,14 @@ Stolen from https://depp.brause.cc/dotemacs"
 #+END_SRC
 
 *** Bind the defuns
-I have only been able to get these to work when they are within an add-hook lambda.
+:PROPERTIES:
+:ID:       314c137f-3674-4194-ae85-8fdb3c2edd32
+:END:
+I have only been able to get these to work when they are within an add-hook lambda.  See [[id:325c01c5-b877-4281-adff-ea956bdb5f2c][Send on Close-Paren]].
 #+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 ")" '(re/send-on-close-paren 'eshell-send-input))
             (keymap-set eshell-mode-map "C-d" 'eshell-quit-or-delete-char)))
 #+END_SRC
 
@@ -1470,14 +1469,9 @@ I have only been able to get these to work when they are within an add-hook lamb
 :ID:       e7a7b861-8f63-4036-9f68-59fb954a7561
 :END:
 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]].
+*** Binding to start IELM
 #+BEGIN_SRC emacs-lisp
-(defun re/ielm-send-on-close-paren ()
-  "Makes ielm act somewhat like genera.
-Makes a closing paren execute the sexp."
-  (interactive)
-  (re/send-on-close-paren 'ielm-send-input))
+(keymap-global-set "C-c i" 'ielm)
 #+END_SRC
 
 *** Persistent command history
@@ -1506,13 +1500,15 @@ Makes a closing paren execute the sexp."
 #+END_SRC
 
 *** Bindings
-~C-l~ to clear buffer, send on close paren.
+:PROPERTIES:
+:ID:       8e0a0ad5-ba71-4a73-a739-4754b37edb7f
+:END:
+~C-l~ to clear buffer, See [[id:325c01c5-b877-4281-adff-ea956bdb5f2c][Send on Close-Paren]].
 #+BEGIN_SRC emacs-lisp
-(keymap-global-set "C-c i" 'ielm)
 (add-hook 'ielm-mode-hook
           (lambda ()
             (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)))
+            (keymap-set inferior-emacs-lisp-mode-map ")" '(re/send-on-close-paren 'ielm-send-input))))
 #+END_SRC
 
 ** Customize system
index 26ed6d837f910e58fc3ecfd96612e6858804bc70..cf8cf3a7a58d8a974c2942277b5ff1936fd73bb8 100644 (file)
@@ -7,8 +7,14 @@
 (setq gc-cons-threshold most-positive-fixnum
       gc-cons-percentage 0.6)
 
-;; (add-hook 'after-init-hook #'(lambda () (setq gc-cons-threshold (* 1024 1024 25)
-;;                                          gc-cons-percentage 0.1)))
+(add-hook 'after-init-hook #'(lambda () (setq gc-cons-threshold (* 800 1000)
+                                         gc-cons-percentage 0.1
+                                         garbage-collection-messages t)))
+
+(setq default-directory "~/")
+
+(provide 'early-init)
+;;; hic terminatur early-init.el
 
 (menu-bar-mode -1)
 (tool-bar-mode -1)
@@ -19,8 +25,3 @@
       server-client-instructions nil
       frame-resize-pixelwise t
       initial-scratch-message (message ";;; Emacs loaded in %s.\n\n" (emacs-init-time)))
-
-(setq default-directory "~/")
-
-(provide 'early-init)
-;;; hic terminatur early-init.el