From: "Mark E. Shoulson" <mark@kli.org>
To: org-mode mailing list <emacs-orgmode@gnu.org>
Subject: "Smart" quotes
Date: Mon, 21 May 2012 23:32:26 -0400 [thread overview]
Message-ID: <4FBB08CA.5060705@kli.org> (raw)
[-- Attachment #1: Type: text/html, Size: 1675 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: smartquotes2.patch --]
[-- Type: text/x-patch; name="smartquotes2.patch", Size: 2277 bytes --]
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)
[-- Attachment #3: ChangeLog --]
[-- Type: text/plain, Size: 159 bytes --]
2012-05-21 Mark Shoulson <mark@kli.org>
* lisp/org.el, lisp/org-entities.el: added org-smart-quotes
for displaying ' and " characters as "smart quotes."
next reply other threads:[~2012-05-22 3:32 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-22 3:32 Mark E. Shoulson [this message]
2012-05-23 22:17 ` "Smart" quotes Nicolas Goaziou
2012-05-24 3:05 ` Mark E. Shoulson
2012-05-25 17:14 ` Nicolas Goaziou
2012-05-25 17:51 ` Jambunathan K
2012-05-25 22:51 ` Mark E. Shoulson
2012-05-26 6:48 ` Nicolas Goaziou
2012-05-29 1:30 ` Mark E. Shoulson
2012-05-29 17:57 ` Nicolas Goaziou
2012-05-30 0:51 ` Mark E. Shoulson
2012-05-31 1:50 ` (no subject) Mark Shoulson
2012-05-31 13:38 ` Nicolas Goaziou
2012-05-31 23:26 ` Smart Quotes Exporting (Was: Re: (no subject)) Mark E. Shoulson
2012-06-01 17:11 ` Smart Quotes Exporting Nicolas Goaziou
2012-06-01 22:41 ` Mark E. Shoulson
2012-06-03 3:16 ` Mark E. Shoulson
2012-06-06 2:14 ` Mark E. Shoulson
2012-06-07 19:21 ` Nicolas Goaziou
2012-06-11 1:28 ` Mark Shoulson
2012-06-12 13:21 ` Nicolas Goaziou
2012-06-15 16:20 ` Mark Shoulson
2012-06-19 9:26 ` Nicolas Goaziou
2012-08-07 23:18 ` Bastien
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FBB08CA.5060705@kli.org \
--to=mark@kli.org \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).