Add functionality for typographic quotes

Finally getting around to adding nicer quotes from Artur's Endless
Parenthesis blog. Org is getting prettier and prettier.
This commit is contained in:
Howard Abrams 2022-02-17 09:50:34 -08:00
parent 620a1bf670
commit 8b53a1654f
2 changed files with 85 additions and 3 deletions

View file

@ -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-src-fontify-natively t ;; Pretty code blocks
org-hide-emphasis-markers t) org-hide-emphasis-markers t)
#+END_SRC #+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 isnt 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 shouldnt 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 * 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). I really want to use the Org Beautify package, but it overrides my darker themes (and all I really want is headlines to behave).

View file

@ -26,8 +26,7 @@ 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. Org is a /large/ complex beast with a gazillion settings, so I discuss these later in this document.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package org (use-package org
:straight (:type built-in) ; Problems with the 9.4.4 version ;; :straight (:type built-in) ; Use with problems from 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 :mode ("\\.org" . org-mode) ; Addresses an odd warning
:init :init
<<variables>> <<variables>>
@ -431,6 +430,12 @@ Let's hook some spell-checking into org files, and actually all text files. We'l
(use-package flyspell (use-package flyspell
:hook (text-mode . flyspell-mode) :hook (text-mode . flyspell-mode)
:bind ("M-S" . ha-fix-last-spelling) :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 :config
(defun ha-fix-last-spelling (count) (defun ha-fix-last-spelling (count)
"Jump to the last misspelled word, and correct it." "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 p" '("previous misspell" . evil-prev-flyspell-error)
"s n" '("next misspell" . evil-next-flyspell-error))) "s n" '("next misspell" . evil-next-flyspell-error)))
#+END_SRC #+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. 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. Isnt this nice?
Of course I need a thesaurus, and I'm installing [[https://github.com/SavchenkoValeriy/emacs-powerthesaurus][powerthesaurus]]: Of course I need a thesaurus, and I'm installing [[https://github.com/SavchenkoValeriy/emacs-powerthesaurus][powerthesaurus]]:
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp