From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Mark E. Shoulson" Subject: "Smart" quotes Date: Mon, 21 May 2012 23:32:26 -0400 Message-ID: <4FBB08CA.5060705@kli.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------070000070508050008070701" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:51838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWfpv-0002Xo-5o for emacs-orgmode@gnu.org; Mon, 21 May 2012 23:32:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SWfpr-0001O2-Ro for emacs-orgmode@gnu.org; Mon, 21 May 2012 23:32:38 -0400 Received: from pi.meson.org ([96.56.207.26]:42236) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1SWfpr-0001M9-Mg for emacs-orgmode@gnu.org; Mon, 21 May 2012 23:32:35 -0400 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: org-mode mailing list This is a multi-part message in MIME format. --------------070000070508050008070701 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit

(I seem to be winding up fixating on non-asciisms for org-mode; strange)

"Smart" quotes can be annoying when they aren't smart enough.  But when they work you can miss them.  I'm attaching a patch that defines a custom variable org-smart-quotes (nil by default), which when non-nil causes the " and ' characters to display as “smart” quotes, hopefully the right ones.  They're still ' and " in the underlying text, just overlaid with “”.


I started working on parallel patches on the export end (in the -e- files in contrib); it would really help org-mode's standing as a lightweight markup language, imo, but then I saw that's already underway; I had just looked in the wrong exports.


I also note that my post here dated May 9 (http://article.gmane.org/gmane.emacs.orgmode/55756 ) has gone completely without comment, good or bad.  Did I miss something?  Did it not get through (it shows up on gmane)?  At least one of the changes submitted there I would think is pretty uncontroversial.


~mark


--------------070000070508050008070701 Content-Type: text/x-patch; name="smartquotes2.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="smartquotes2.patch" diff --git a/lisp/org-entities.el b/lisp/org-entities.el index 8b5b3f3..ee54abc 100644 --- a/lisp/org-entities.el +++ b/lisp/org-entities.el @@ -47,6 +47,14 @@ in backends where the corresponding character is not available." :version "24.1" :type 'boolean) +(defcustom org-smart-quotes nil + "Non-nil means display ' and \" characters as Unicode \"smart\" quotes. +Org-mode will try to figure out if a quote character is opening or closing. + +Note: this does not affect export, only on-screen appearance." + :group 'org-entities + :type 'boolean) + (defcustom org-entities-user nil "User-defined entities used in Org-mode to produce special characters. Each entry in this list is a list of strings. It associates the name diff --git a/lisp/org.el b/lisp/org.el index 05f5375..213490e 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5926,6 +5926,7 @@ needs to be inserted at a specific position in the font-lock sequence.") '(1 'org-archived prepend)) ;; Specials '(org-do-latex-and-special-faces) + '(org-smartify-quotes) '(org-fontify-entities) '(org-raise-scripts) ;; Code @@ -5948,6 +5949,33 @@ needs to be inserted at a specific position in the font-lock sequence.") '(org-font-lock-keywords t nil nil backward-paragraph)) (kill-local-variable 'font-lock-keywords) nil)) +(defconst org-smart-quotes-regex + ;; ' is a word character, " is punctuation. + "\\(\"\\<\\)\\|\\>\\s.*\\(\"\\)\\|\\(?:\\W\\|^\\)\\('\\)\\|\\w\\s.*\\('\\)") + + +(defun org-smartify-quotes (limit) + "Make 'smart quotes' out of straight quotes." + (let* (start end subst k) + (when org-smart-quotes + (catch 'match + (while (re-search-forward org-smart-quotes-regex + limit t) + (cond ((match-string 1) + (setq k 1 subst "“")) + ((match-string 2) + (setq k 2 subst "”")) + ((match-string 3) + (setq k 3 subst "‘")) + ((match-string 4) + (setq k 4 subst "’"))) + (add-text-properties (match-beginning k) (match-end k) + (list 'font-lock-fontified t)) + (compose-region (match-beginning k) (match-end k) subst nil) + (backward-char 1) + (throw 'match t)) + nil)))) + (defun org-toggle-pretty-entities () "Toggle the composition display of entities as UTF8 characters." (interactive) --------------070000070508050008070701 Content-Type: text/plain; charset=UTF-8; name="ChangeLog" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ChangeLog" 2012-05-21 Mark Shoulson * lisp/org.el, lisp/org-entities.el: added org-smart-quotes for displaying ' and " characters as "smart quotes." --------------070000070508050008070701--