elisp-as-a-drug.org (4917B)
1 #+title: Elisp as a drug 2 #+date: <2020-09-16 Wed> 3 4 A correspondent (dare I say /homie/) of mine, [[https://brettgilio.com][Brett Gilio]] of 5 [[https://sr.ht/~brettgilio/org-webring][org-webring]], recently posted this on Mastodon: 6 7 #+begin_quote 8 Emacs Lisp isn't a language, it's a drug addiction. It isn't healthy, 9 it will divide your family. You don't love it, yet you can't refuse 10 it. However, when it works it works just right. 11 https://mstdn.social/@brettgilio/104826971647671358 12 #+end_quote 13 14 Now, this is obviously a joke... right? Of course, I initially 15 thought of it as such -- I had a wee chuckle, and then went about my 16 day. But now, as I'm hacking away on my little Elisp projects, I 17 can't help but consider that there may be some truth in these words. 18 19 I've been sick for the last week-and-a-half or so, and I've got shit 20 to do: watch my lectures, write my essays, practice my pieces, etc. 21 But I have to admit I've been wasting more time than I should on 22 Elisp. In the span of two days, I wrote three packages just as a form 23 of procrastination. 24 25 * My new packages 26 ** [[https://git.jamzattack.xyz/lex-hl][lex-hl]] 27 A package I've been wanting to write for a while now, I always wanted 28 something to highlight local variables. 208 lines. 29 30 ** [[https://git.jamzattack.xyz/org-el-index][org-el-index]] 31 While writing [[*[[https://git.jamzattack.xyz/lex-hl\][lex-hl]\]][lex-hl]], I decided I wanted to create a list of commands 32 for the readme. I knew that [[https://sr.ht/~brettgilio/org-webring][org-webring]] had one, so I looked around 33 for something to generate such a list. Alas, people just do it 34 manually. What the heck. 35 36 I couldn't be bothered copying docstrings and function names for two 37 whole minutes. So of course I decided it'd be worthwhile to spend a 38 few hours making an automatic version. Well, it works, and I can now 39 press =C-c M-i= to insert an index[fn:1]. 265 lines. 40 41 ** [[https://git.jamzattack.xyz/insert-date][insert-date]] 42 I version all my Elisp packages with the format =%Y.%m.%d=. This is 43 very convenient, because I don't need to worry about making up a 44 "real" version number -- I can just press =C-c ==[fn:2] every time I 45 make a commit and make sure that the date is updated. 46 47 While writing [[*[[https://git.jamzattack.xyz/org-el-index\][org-el-index]\]][org-el-index]], I decided to tag significant commits. But 48 there's no way I'd waste 3 seconds[fn:3] copying the version just to paste 49 it into the minibuffer. So, again, I wrote another package to make 50 this easier. Very good, now I can press =C-c d v= and insert a 51 timestamp in the format I wanted. 83 lines. By far the least 52 wasteful of the three. 53 54 * But it's worth it! Think about the WoRKfLoW gains! 55 Fuck no it isn't! 56 57 Emacs, in all its extensible, introspectable, hackable, blah blah blah 58 glory, has made me its goddamn slave. I wish with all my heart that I 59 could just put up with the fact that it takes an extra couple of 60 seconds to copy the version into the magit tag prompt. That is how 61 humans are supposed to work. 62 63 I shouldn't be wasting my time writing Elisp. I just want to be able 64 to do my work, and not worry about whether a repetitive sequences of 65 keypresses can be turned into its own program. Unfortunately, this 66 seems to be damn near impossible. 67 68 * Footnotes 69 70 [fn:1] In fact, org-el-index provides three functions depending on 71 how much you want to index: 72 73 - *Function*: ([[help:org-el-index-file-large][org-el-index-file-large]] (file)) 74 75 Generate a large org mode index for the definitions in FILE. 76 This includes all supported definitions. 77 78 - *Function*: ([[help:org-el-index-file-medium][org-el-index-file-medium]] (file)) 79 80 Generate a medium org mode index for the definitions in FILE. 81 This includes all definitions unless their name contains "--" 82 83 - *Function*: ([[help:org-el-index-file-small][org-el-index-file-small]] (file)) 84 85 Generate a small org mode index for the definitions in FILE. 86 This includes only custom options and interactive commands. 87 88 [fn:2] Update version, in my package [[https://git.jamzattack.xyz/selime][selime]]: 89 #+begin_src emacs-lisp 90 (defun selime-insert-version () 91 "Update or insert a version number in an Elisp file. 92 Uses the current date formatted as %Y.%m.%d (e.g. 1970.01.01)." 93 (interactive) 94 (declare (interactive-only t)) 95 (let ((new-version (format-time-string " %Y.%m.%d"))) 96 (save-excursion 97 (save-restriction 98 (widen) 99 (goto-char (point-min)) 100 (or (re-search-forward "^;; Version:" nil t) 101 (when (y-or-n-p "Add a version? ") 102 (goto-char (point-min)) 103 (or (re-search-forward "^;; Author:" nil t) 104 (user-error "No version or author statement found. Try `auto-insert'")) 105 (forward-line 1) 106 (insert ";; Version:\n\n") 107 (forward-char -2))) 108 (kill-line) 109 (insert new-version))))) 110 #+end_src 111 112 [fn:3] Seriously, this would only take 3 seconds: 113 114 =M-<= =C-s= =RET= =version:= =RET= =C-M-SPC= =M-w=