From 8b53a1654f7baaf20f3e52a4bcfa2b29b677d553 Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Thu, 17 Feb 2022 09:50:34 -0800 Subject: [PATCH] Add functionality for typographic quotes Finally getting around to adding nicer quotes from Artur's Endless Parenthesis blog. Org is getting prettier and prettier. --- ha-org-word-processor.org | 52 +++++++++++++++++++++++++++++++++++++++ ha-org.org | 36 ++++++++++++++++++++++++--- 2 files changed, 85 insertions(+), 3 deletions(-) diff --git a/ha-org-word-processor.org b/ha-org-word-processor.org index 8476a71..6e2875d 100644 --- a/ha-org-word-processor.org +++ b/ha-org-word-processor.org @@ -35,6 +35,58 @@ Since I use ellipsis in my writing... I like to /change/ how org renders a colla org-src-fontify-natively t ;; Pretty code blocks org-hide-emphasis-markers t) #+END_SRC +** Typographic Quotes +According to [[http://endlessparentheses.com/prettify-your-quotation-marks.html][Artur Malabarba]] of [[http://endlessparentheses.com/prettify-you-apostrophes.html][Endless Parenthesis]] blog, I type a /straight quote/, ", Emacs actually inserts Unicode rounded quotes, like “this”. This idea isn’t how a file is /displayed/, but actually how the file is /made/. Time will tell if this idea works with my auxiliary functions on my phone, like [[https://play.google.com/store/apps/details?id=com.orgzly&hl=en_US&gl=US][Orgzly]] and [[https://github.com/amake/orgro][Orgro]]. + +Stealing his function so that “quotes” just work to insert /rounded/ quotation marks: + +#+BEGIN_SRC emacs-lisp +(define-key org-mode-map "\"" #'endless/round-quotes) + +(defun endless/round-quotes (italicize) + "Insert “” and leave point in the middle. +With prefix argument ITALICIZE, insert /“”/ instead +\(meant for org-mode). +Inside a code-block, just call `self-insert-command'." + (interactive "P") + (if (and (derived-mode-p 'org-mode) + (org-in-block-p '("src" "latex" "html"))) + (call-interactively #'self-insert-command) + (if (looking-at "”[/=_\\*]?") + (goto-char (match-end 0)) + (when italicize + (if (derived-mode-p 'markdown-mode) + (insert "__") + (insert "//")) + (forward-char -1)) + (insert "“”") + (forward-char -1)))) +#+END_SRC + +Stealing function for automatically adding a single quote (not in pairs): + +#+BEGIN_SRC emacs-lisp +(define-key org-mode-map "'" #'endless/apostrophe) + +(defun endless/apostrophe (opening) + "Insert ’ in prose or `self-insert-command' in code. +With prefix argument OPENING, insert ‘’ instead and +leave point in the middle. +Inside a code-block, just call `self-insert-command'." + (interactive "P") + (if (and (derived-mode-p 'org-mode) + (org-in-block-p '("src" "latex" "html"))) + (call-interactively #'self-insert-command) + (if (looking-at "['’][=_/\\*]?") + (goto-char (match-end 0)) + (if (null opening) + (insert "’") + (insert "‘’") + (forward-char -1))))) +#+END_SRC +Quote: “From this time forward, I shouldn’t have to worry about quotes.” + +*Note:* I still need to worry about how quotes affect [[file:ha-org.org::*Spell Checking][spell checking]]. * Org Beautify I really want to use the Org Beautify package, but it overrides my darker themes (and all I really want is headlines to behave). diff --git a/ha-org.org b/ha-org.org index 3221ff3..29cbd34 100644 --- a/ha-org.org +++ b/ha-org.org @@ -26,9 +26,8 @@ A literate programming file for configuring org-mode and those files. Org is a /large/ complex beast with a gazillion settings, so I discuss these later in this document. #+BEGIN_SRC emacs-lisp (use-package org - :straight (:type built-in) ; Problems with the 9.4.4 version - ;; :straight (:type git :protocol ssh :repo "git://git.sv.gnu.org/emacs/org-mode.git") - :mode ("\\.org" . org-mode) ; Addresses an odd warning + ;; :straight (:type built-in) ; Use with problems from 9.4.4 version + :mode ("\\.org" . org-mode) ; Addresses an odd warning :init <> <> @@ -431,6 +430,12 @@ Let's hook some spell-checking into org files, and actually all text files. We'l (use-package flyspell :hook (text-mode . flyspell-mode) :bind ("M-S" . ha-fix-last-spelling) + :init + ;; Tell ispell.el that ’ can be part of a word. + (setq ispell-local-dictionary-alist + `((nil "[[:alpha:]]" "[^[:alpha:]]" + "['\x2019]" nil ("-B") nil utf-8))) + :config (defun ha-fix-last-spelling (count) "Jump to the last misspelled word, and correct it." @@ -445,8 +450,33 @@ Let's hook some spell-checking into org files, and actually all text files. We'l "s p" '("previous misspell" . evil-prev-flyspell-error) "s n" '("next misspell" . evil-next-flyspell-error))) #+END_SRC + Sure, the keys, ~[ s~ and ~] s~ can jump to misspelled words, and use ~M-$~ to correct them, but I'm getting used to these leaders. +According to [[http://endlessparentheses.com/ispell-and-apostrophes.html][Artur Malabarba]], we can turn on rounded apostrophe's, like =‘= (left single quotation mark). The idea is to not send the quote to the sub-process: + +#+BEGIN_SRC emacs-lisp + (defun endless/replace-apostrophe (args) + "Don't send ’ to the subprocess." + (cons (replace-regexp-in-string + "’" "'" (car args)) + (cdr args))) + + (advice-add #'ispell-send-string :filter-args #'endless/replace-apostrophe) + + (defun endless/replace-quote (args) + "Convert ' back to ’ from the subprocess." + (if (not (derived-mode-p 'org-mode)) + args + (cons (replace-regexp-in-string + "'" "’" (car args)) + (cdr args)))) + + (advice-add #'ispell-parse-output :filter-args #'endless/replace-quote) +#+END_SRC + +The end result? No misspellings. Isn‘t this nice? + Of course I need a thesaurus, and I'm installing [[https://github.com/SavchenkoValeriy/emacs-powerthesaurus][powerthesaurus]]: #+BEGIN_SRC emacs-lisp