Emacs
Much Ado About Emacs 015
I got distracted by MojoPad and Kosshi for a while there. Emacs has been plugging away. Always launched. Always handling my writing. It is the centerpiece of my efforts. I have been making changes to it. Nothing too big, but designed to improve my experience in it. I will talk about three of those in this article.
Whitespace
I like seeing the marks for return and tabs. Returns are valid for every file but tabs are valid for only content which is copied from other programs or sources. I like seeing them. I made sure that they show up in Emacs.
(setq whitespace-style '(face ; Use faces to colorize
tabs ; Look for tabs
tab-mark ; Visualise tabs
newline ; Look for newlines
newline-mark)) ; Visualise newlines
;; trailing)) ; (Optional) Still show ugly trailing spaces
(setq whitespace-display-mappings
'(
;; Customize the tab marker
;; 9 is the ASCII code for Tab.
;; ?\u2192 is the Unicode character '→' (Rightwards Arrow).
;; [?\n] is the fallback if the arrow can't be rendered.
(tab-mark 9 [?\u2192 ?\t] [?\t])
;; Customize the newline/return marker
;; 10 is the ASCII code for Newline (Line Feed).
;; ?\u21b5 is the Unicode character '↵' (Downwards Arrow with Corner Left).
(newline-mark 10 [?\u21b5 ?\n] [?\n])
))
Minimal Mode Line
I had been using doom modeline and had a elaborate configuration setup for that. See Much Ado About Emacs 001 - Bicycle For Your Mind.
Decided to make it simpler:
(defun my-modeline-file-path ()
"Return abbreviated file path if visiting a file."
(when-let ((file (buffer-file-name)))
(format " (%s)" (abbreviate-file-name (file-name-directory file)))))
(setq-default mode-line-format
'("%e"
"%* "
my-modeline-buffer-name
(:eval (my-modeline-file-path)) ;; Displays " (~/projects/app/)"
mode-line-format-right-align
"L%l (%p)"
" "
my-modeline-major-mode))
(defvar-local my-modeline-buffer-name
'(:eval
(when (mode-line-window-selected-p)
(propertize (format " %s " (buffer-name))))))
(put 'my-modeline-buffer-name 'risky-local-variable t)
(defvar-local my-modeline-major-mode
'(:eval
(list
(propertize "λ" 'face 'shadow)
" "
(propertize (capitalize (symbol-name major-mode)) 'face 'bold)))
"Mode line construct to display the major mode.")
(put 'my-modeline-major-mode 'risky-local-variable t)
Only the information I need, and none of the information I don’t. Looks pretty and minimal too. Added benefit? No external package.
Two Spaces Turn Into a Period and Space. Next Letter Gets Capitalized.
I have picked up some bad habits. Two spaces turns into a period, and the next letter is automatically capitalized. macOS lets me do this automatically in some programs. Not Emacs. I needed to rectify that.
;; two spaces to a period
(defun my/double-space-to-period-and-capitalize ()
"Convert double space to '. ' and capitalize the next typed character."
(interactive)
(if (and (eq (char-before) ?\s)
(not (eq (char-before (1- (point))) ?\s)))
(progn
(delete-char -1)
(insert ". ")
;; Read the next key press directly
(let ((evt (read-event)))
(if (characterp evt)
;; If it's a character, insert its uppercase version
(insert (upcase (char-to-string evt)))
;; If it's a special key (like an arrow key, backspace, etc.), unread it
(setq unread-command-events (list evt)))))
(insert " ")))
;; Enable in text-mode (Org, Markdown, Plain text)
(add-hook 'text-mode-hook
(lambda ()
(local-set-key (kbd "SPC") #'my/double-space-to-period-and-capitalize)))
That is all I have for today.
macosxguru at the gmail thingie.