Also make a defun/binding to toggle it as needed.
#+BEGIN_SRC emacs-lisp
-(defun toggle-visual-fill-column-mode ()
+(defun re/toggle-visual-fill-column-mode ()
"Toggles `visual-fill-column-mode."
(interactive)
(visual-fill-column-mode 'toggle))
-(keymap-global-set "C-c v" 'toggle-visual-fill-column-mode)
+(keymap-global-set "C-c v" 're/toggle-visual-fill-column-mode)
#+END_SRC
: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 c-lineup-arglist-tabs-only (ignored)
+(defun re/c-lineup-arglist-tabs-only (ignored)
"Line up argument lists by tabs, not spaces. Stolen from https://kernel.org/doc/html/v4.10/process/coding-style.html"
(let* ((anchor (c-langelem-pos c-syntactic-element))
(column (c-langelem-2nd-pos c-syntactic-element))
(c-offsets-alist
(arglist-cont-nonempty
c-lineup-gcc-asm-reg
- c-lineup-arglist-tabs-only))))))
+ re/c-lineup-arglist-tabs-only))))))
(add-hook 'c-mode-hook
(lambda ()
:END:
I took this from [[https://whattheemacsd.com][whattheemacsd.com]]. It is occasionally handy.
#+BEGIN_SRC emacs-lisp
-(defun rename-current-buffer-file ()
+(defun re/rename-current-buffer-file ()
"Renames the current buffer and the file it is visiting."
(interactive)
(let ((name (buffer-name))
(message "File '%s' successfully renamed to '%s'"
name (file-name-nondirectory new-name)))))))
-(keymap-global-set "C-x C-r" 'rename-current-buffer-file)
+(keymap-global-set "C-x C-r" 're/rename-current-buffer-file)
#+END_SRC
**** Buffer Menu
:PROPERTIES:
: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 scratch-only ()
+(defun re/scratch-only ()
"Bring up the scratch buffer as the only visible buffer."
(interactive)
(scratch-buffer)
(delete-other-windows))
(keymap-global-set "<f5>" 'scratch-buffer)
-(keymap-global-set "S-<f5>" 'scratch-only)
+(keymap-global-set "S-<f5>" 're/scratch-only)
#+END_SRC
**** Line joining
: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 backward-join-line ()
+(defun re/backward-join-line ()
"A wrapper for join-line to make it go in the right direction."
(interactive)
(join-line 0))
-(keymap-global-set "M-j" 'backward-join-line)
+(keymap-global-set "M-j" 're/backward-join-line)
#+END_SRC
**** Line opening
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
-(defun open-line-below (n)
+(defun re/open-line-below (n)
"Creates a new empty line below the current line and moves to it."
(interactive "*p")
(end-of-line)
(call-interactively (next-line))
(indent-for-tab-command))
-(defun open-line-above (n)
+(defun re/open-line-above (n)
"Creates a new empty line above the current line."
(interactive "*p")
(beginning-of-line)
I Bind the previous functions to =C-o= and =M-o=.
#+BEGIN_SRC emacs-lisp
-(keymap-global-set "C-o" 'open-line-below)
-(keymap-global-set "M-o" 'open-line-above)
+(keymap-global-set "C-o" 're/open-line-below)
+(keymap-global-set "M-o" 're/open-line-above)
#+END_SRC
**** Commenting
:END:
I stole this directly from [[https://depp.brause.cc/dotemacs][depp.brause.cc/dotemacs]]. Very good, simple solution.
#+BEGIN_SRC emacs-lisp
-(defun my-comment-dwim ()
+(defun re/comment-dwim ()
"Comment region if active, otherwise comment line.
Stolen from https://depp.brause.cc/dotemacs"
(interactive)
(comment-or-uncomment-region (line-beginning-position)
(line-end-position))))
-(keymap-global-set "M-;" 'my-comment-dwim)
+(keymap-global-set "M-;" 're/comment-dwim)
#+END_SRC
**** Killing
I didn't want to re-bind =C-w= away from =kill-region=, so I made it do both.
#+BEGIN_SRC emacs-lisp
-(defun kill-bword-or-region ()
+(defun re/kill-bword-or-region ()
"Kill region if active, otherwise kill back one word."
(interactive)
(if (use-region-p)
(call-interactively 'kill-region)
(call-interactively 'backward-kill-word)))
-(keymap-global-set "C-w" '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=.
#+BEGIN_SRC emacs-lisp
-(defun backward-kill-line ()
+(defun re/backward-kill-line ()
"Kill back to beginning of line from point."
(interactive)
(kill-line 0))
-(keymap-global-set "C-u" 'backward-kill-line)
+(keymap-global-set "C-u" 're/backward-kill-line)
#+END_SRC
Since =C-u= is =universal-argument=, I put that functionality on =M-'=.
:END:
I have the infamous =smart-beginning-of-line= command here.
#+BEGIN_SRC emacs-lisp
-(defun smart-beginning-of-line ()
+(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."
: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 smart-beginning-of-visual-line ()
+(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
: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] 'smart-beginning-of-line)
+(global-set-key [remap move-beginning-of-line] 're/smart-beginning-of-line)
(add-hook 'visual-line-mode-hook
(lambda ()
- (keymap-global-set "C-a" 'smart-beginning-of-visual-line)))
+ (keymap-global-set "C-a" 're/smart-beginning-of-visual-line)))
#+END_SRC
***** Line Numbers on move only
:PROPERTIES:
: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 my-goto-line ()
+(defun re/goto-line ()
"Show line numbers before going to line, then hide them again."
(interactive)
(display-line-numbers-mode 1)
(call-interactively 'goto-line)
(display-line-numbers-mode -1))
-(global-set-key [remap goto-line] 'my-goto-line)
+(global-set-key [remap goto-line] 're/goto-line)
#+END_SRC
***** Other window or split window
:PROPERTIES:
: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 other-window-or-split-window (&optional window)
+(defun re/other-window-or-split-window (&optional window)
(interactive)
(if (= (count-windows) 1)
(funcall split-window-preferred-function window)
(other-window 1)))
-(keymap-global-set "C-M-o" 'other-window-or-split-window)
+(keymap-global-set "C-M-o" 're/other-window-or-split-window)
#+END_SRC
**** Search and Replace
:PROPERTIES:
: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
#+BEGIN_SRC emacs-lisp
-(defun send-on-close-paren (executor)
+(defun 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)
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)
- (defun unfuck-aveva-license ()
+ (defun re/unfuck-aveva-license ()
"Remove the offending xml files.
Use this when aveva can't find ass with both hands."
(interactive)
: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 org-agenda-show-custom (&optional arg)
+(defun re/org-agenda-show-custom (&optional arg)
"Show my custom agenda."
(interactive "P")
(org-agenda arg " "))
Do it again for main agenda
#+BEGIN_SRC emacs-lisp
-(defun org-show-agenda (&optional arg)
+(defun re/org-show-agenda (&optional arg)
"Show the main agenda"
(interactive "P")
(org-agenda arg "a"))
: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: (org-auto-archive) -*-
+-*- after-save-hook: (re/org-auto-archive) -*-
#+END_SRC
#+BEGIN_SRC emacs-lisp
-(defun org-auto-archive ()
+(defun re/org-auto-archive ()
"Automatically archive completed tasks in an org file.
Intended for use as an after-save-hook."
(interactive)
Also add that defun to =safe-local-variables= so that emacs will run it.
#+BEGIN_SRC emacs-lisp
-(setq safe-local-variable-values '((after-save-hook org-auto-archive)))
+(setq safe-local-variable-values '((after-save-hook re/org-auto-archive)))
#+END_SRC
*** Auto-Generate IDs
: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 org-auto-generate-ids-in-file ()
+(defun re/org-auto-generate-ids-in-file ()
"Add ID properties to all headlines in the current
file which do not already have one."
(interactive)
#+BEGIN_SRC emacs-lisp
(add-hook 'org-mode-hook
(lambda ()
- (add-hook 'before-save-hook 'org-auto-generate-ids-in-file nil 'local)))
+ (add-hook 'before-save-hook 're/org-auto-generate-ids-in-file nil 'local)))
#+END_SRC
*** Tangling
:END:
Make a function to tangle this file, and run it on save.
#+BEGIN_SRC emacs-lisp
-(defun tangle-init ()
+(defun re/tangle-init ()
"Tangle and compile init.org.
Stolen from https://github.com/larstvei/dot-emacs."
(when (equal (buffer-file-name)
(let ((prog-mode-hook nil))
(org-babel-tangle))))
-(add-hook 'after-save-hook 'tangle-init)
+(add-hook 'after-save-hook 're/tangle-init)
#+END_SRC
*** Bindings
(keymap-global-set "C-c a" 'org-agenda)
(keymap-global-set "C-c c" 'org-capture)
(keymap-global-set "C-c b" 'org-switchb)
-(keymap-global-set "<f8>" 'org-agenda-show-custom)
-(keymap-global-set "<f6>" 'org-show-agenda)
+(keymap-global-set "<f8>" 're/org-agenda-show-custom)
+(keymap-global-set "<f6>" 're/org-show-agenda)
#+END_SRC
**** Mode-Specific
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 eshell-send-on-close-paren ()
+(defun re/eshell-send-on-close-paren ()
"Makes eshell act somewhat like genera.
Makes a closing paren execute the sexp."
(interactive)
- (send-on-close-paren 'eshell-send-input))
+ (re/send-on-close-paren 'eshell-send-input))
#+END_SRC
*** Quit or delete-char
#+BEGIN_SRC emacs-lisp
(add-hook 'eshell-mode-hook
(lambda ()
- (keymap-set eshell-mode-map ")" 'eshell-send-on-close-paren)
+ (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
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 ielm-send-on-close-paren ()
+(defun re/ielm-send-on-close-paren ()
"Makes ielm act somewhat like genera.
Makes a closing paren execute the sexp."
(interactive)
- (send-on-close-paren 'ielm-send-input))
+ (re/send-on-close-paren 'ielm-send-input))
#+END_SRC
*** Persistent command history
:PROPERTIES:
:ID: 6db9d990-00e7-44ec-a83c-b2999fa8db73
:END:
#+BEGIN_SRC emacs-lisp
-(defun g-ielm-init-history ()
+(defun re/ielm-init-history ()
"Stolen from https://n16f.net/blog/making-ielm-more-comfortable."
(let ((path (expand-file-name "ielm/history" user-emacs-directory)))
(make-directory (file-name-directory path) t)
comint-input-ignoredups t)
(comint-read-input-ring))
-(add-hook 'ielm-mode-hook 'g-ielm-init-history)
+(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 g-ielm-write-history (&rest _args)
+(defun re/ielm-write-history (&rest _args)
"Stolen from https://n16f.net/blog/making-ielm-more-comfortable."
(with-file-modes #o600
(comint-write-input-ring)))
-(advice-add 'ielm-send-input :after 'g-ielm-write-history)
+(advice-add 'ielm-send-input :after 're/ielm-write-history)
#+END_SRC
*** Bindings
:PROPERTIES:
(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 ")" 'ielm-send-on-close-paren)))
+ (keymap-set inferior-emacs-lisp-mode-map ")" 're/ielm-send-on-close-paren)))
#+END_SRC
** Customize system
:PROPERTIES: