emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Mark Shoulson <mark@kli.org>
To: emacs-orgmode@gnu.org
Subject: Re: (no subject)
Date: Thu, 31 May 2012 01:50:39 +0000 (UTC)	[thread overview]
Message-ID: <loom.20120531T025544-595@post.gmane.org> (raw)
In-Reply-To: 4FC56F1B.5040201@kli.org

Mark E. Shoulson <mark <at> kli.org> writes:


> 
> All right, bottom line, this is sort of what I'm seeing.  I'm not 100% 
> sure which files should house these things, but something like this:
> 
> 1) a variable containing for each language regexp for each of: open 
> double-quote, close double-quote, open single-quote, close single-quote, 
> and maybe mid-word apostrophe.  Odds are these regexps are going to be 
> the same for just about all languages (the regexps detecting them, mind 
> you), so probably should have some sort of default that the alist can 
> just reference.  A language should also be allowed to define other quote 
> regexps in its list too.  We need these to be ordered, with a standard 
> set, so that we can have...
> 
> 2) for each *exporter* (including on-screen display), a variable that 
> defines, for each language, what the *substitution* will be for 
> open-double-quote, close-double-quote, etc.  Other extras can be defined 
> too.  That way we can have an exporter-independent way to detect quotes 
> to be smartified, but each exporter has its own way to smartify them.
> 
> 3) Since most exporters are probably going to be handling doing the 
> process approximately the same (match the regexp, stick in the 
> associated substitution), org-export.el should have a generic function 
> that does this which each exporter *may* call in (or as) its 
> quote-smartifier in its text translator, unless it needs something more 
> specific which it can provide itself.
> 
> In terms of what is handled, the idea in my head is that we would expect 
> the writer to be using " or ' to surround their quotes, regardless of 
> what their native custom is (if they're doing it using their 
> language-specific quote-marks, we don't need to bother with all this 
> anyway).  Goal is to handle either "quotes" or 'quotes' in either 
> nesting (or no nesting, if someone does "quote' for some reason), and 
> with any luck not get too confused with other uses of apostrophe.
> 
> It makes sense to me, but I bet I explained it badly and people are 
> going to have all kinds of issues with it. :)
> 
> No telling when (if?) I'll be able to produce something along these 
> lines, but it's something to start thinking about anyway.
> 
> ~mark
> 
> 


Regarding the "this is what I'm seeing", I paste at the bottom a
preliminary patch.  It is totally *not* worth actually applying it unless you
want to develop this; it's a snapshot mid-development.  But it does seem to
actually work.  The same set of regexps is used, and the same function, though
that is defeasible and an exporter can define its own.  The hardest part was
getting the onscreen versions showing right (also the most recently and probably
best tested, so the actual exporters might be more bumpy).  Actual substitutions
being used are not necessarily typologically sensible; chosen more so it's
easier to see the action of the process.  Nothing is in the right place, things
that should be customizables aren't... it's proof-of-concept. Am I going in the
right direction, as far as export-engine is concerned?

==========

From 420048063e3fd2af1b019c48864d58d82cef62ef Mon Sep 17 00:00:00 2001
From: Mark Shoulson <mark@kli.org>
Date: Tue, 29 May 2012 23:01:12 -0400
Subject: [PATCH] Just barely works, nothing in the right places.  For
 entertainment purposes only.

---
 contrib/lisp/org-e-html.el  |    5 ++++
 contrib/lisp/org-e-latex.el |   53 +++++++++++++++++++++----------------------
 contrib/lisp/org-export.el  |   52 ++++++++++++++++++++++++++++++++++++++++++
 lisp/org.el                 |   50 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 133 insertions(+), 27 deletions(-)

diff --git a/contrib/lisp/org-e-html.el b/contrib/lisp/org-e-html.el
index de98493..b851713 100644
--- a/contrib/lisp/org-e-html.el
+++ b/contrib/lisp/org-e-html.el
@@ -1077,6 +1077,11 @@ in order to mimic default behaviour:
 
 ;;;; Plain text
 
+(defvar org-e-html-quote-replacements
+  '(("fr" "« " " »" "‘" "’" "’")
+    ("en" "“" "”" "‘" "’" "’")
+    ("de" "„" "“" "‚" "‘" "’"))
+
 (defcustom org-e-html-quotes
   '(("fr"
      ("\\(\\s-\\|[[(]\\|^\\)\"" . "«~")
diff --git a/contrib/lisp/org-e-latex.el b/contrib/lisp/org-e-latex.el
index 67e9197..540ebe1 100644
--- a/contrib/lisp/org-e-latex.el
+++ b/contrib/lisp/org-e-latex.el
@@ -687,6 +687,10 @@ during latex export it will output
 
 ;;;; Plain text
 
+(defvar org-e-latex-quote-replacements
+  '(("fr" "«~" "~»" "‹~" "~›" "/!")
+    ("en" "((" "))" ".(" ")." "/")))
+
 (defcustom org-e-latex-quotes
   '(("fr"
      ("\\(\\s-\\|[[(]\\|^\\)\"" . "«~")
@@ -699,25 +703,22 @@ during latex export it will output
   "Alist for quotes to use when converting english double-quotes.
 
 The CAR of each item in this alist is the language code.
-The CDR of each item in this alist is a list of three CONS:
-- the first CONS defines the opening quote;
-- the second CONS defines the closing quote;
-- the last CONS defines single quotes.
+The CDR of each item in this alist is a list of CONS:
+- the first CONS should define the opening quote;
+- the second CONS should define the closing quote;
+- subsequent CONS should define any other quotes, e.g. single, etc.
 
 For each item in a CONS, the first string is a regexp
 for allowed characters before/after the quote, the second
 string defines the replacement string for this quote."
   :group 'org-export-e-latex
-  :type '(list
-	  (cons :tag "Opening quote"
-		(string :tag "Regexp for char before")
-		(string :tag "Replacement quote     "))
-	  (cons :tag "Closing quote"
-		(string :tag "Regexp for char after ")
-		(string :tag "Replacement quote     "))
-	  (cons :tag "Single quote"
-		(string :tag "Regexp for char before")
-		(string :tag "Replacement quote     "))))
+  :type '(repeat
+	  (cons
+	   (string :tag "language code")
+	   (repeat
+	    (cons :tag "Quote"
+		  (string :tag "Regexp ")
+		  (string :tag "Replacement quote     "))))))
 
 
 ;;;; Compilation
@@ -852,19 +853,17 @@ nil."
 	     options
 	     ","))
 
-(defun org-e-latex--quotation-marks (text info)
-  "Export quotation marks depending on language conventions.
-TEXT is a string containing quotation marks to be replaced.  INFO
-is a plist used as a communication channel."
-  (mapc (lambda(l)
-	  (let ((start 0))
-	    (while (setq start (string-match (car l) text start))
-	      (let ((new-quote (concat (match-string 1 text) (cdr l))))
-		(setq text (replace-match new-quote  t t text))))))
-	(cdr (or (assoc (plist-get info :language) org-e-latex-quotes)
-		 ;; Falls back on English.
-		 (assoc "en" org-e-latex-quotes))))
-  text)
+(defun org-e-latex--quotation-marks (text info) 
+  (org-export-quotation-marks text info org-e-latex-quote-replacements))
+  ;; (mapc (lambda(l)
+  ;; 	  (let ((start 0))
+  ;; 	    (while (setq start (string-match (car l) text start))
+  ;; 	      (let ((new-quote (concat (match-string 1 text) (cdr l))))
+  ;; 		(setq text (replace-match new-quote  t t text))))))
+  ;; 	(cdr (or (assoc (plist-get info :language) org-e-latex-quotes)
+  ;; 		 ;; Falls back on English.
+  ;; 		 (assoc "en" org-e-latex-quotes))))
+  ;; text)
 
 (defun org-e-latex--wrap-label (element output)
   "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el
index b9294e5..aacb448 100644
--- a/contrib/lisp/org-export.el
+++ b/contrib/lisp/org-export.el
@@ -284,6 +284,58 @@ rules.")
   :tag "Org Export General"
   :group 'org-export)
 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Probably a defcustom eventually.
+
+;; Each element of this consists of: car=language code, cdr=list of
+;; double-quote-open-regexp, double-quote-close-regexp,
+;; single-quote-open-regexp, single-quote-close-regexp, &optional
+;; single-apostrophe regexp?
+;; Just about all will be the same anyway, so mostly language DEFAULT.
+
+;; For testing purposes, poorly-designed at first.
+(defvar org-export-quotes-regexps
+  '((DEFAULT 
+      "\\(?:\\s-\\|[[(]\\|^\\)\\(\"\\)\\w" 
+      "\\(?:\\S-\\)\\(\"\\)\\s-" 
+      "\\(?:\\s-\\|(\\|^\\)\\('\\)\\w"
+      "\\w\\('\\)\\(?:\\s-\\|\\s.\\|$\\)"
+      "\\w\\('\\)\\w")))
+
+;; Generic function, usable by exporters, but they can define their own
+;; instead.
+(defun org-export-quotation-marks (text info replacements)
+  "Export quotation marks depending on language conventions.
+TEXT is a string containing quotation marks to be replaced.  INFO
+is a plist used as a communication channel."
+  (let* ((start 0)
+	 (regexps 
+	  (cdr 
+	   (or 
+	    (assoc (plist-get info :language)
+		   org-export-quotes-regexps)
+	    (assoc 'DEFAULT org-export-quotes-regexps))))
+	 (subs (cdr (or (assoc (plist-get info :language)
+			       replacements)
+			(assoc "en" replacements))))
+	 (quotes (pairlis regexps subs)))
+    (mapc (lambda (p)
+	    (let ((re (car p))
+		  (su (cdr p)))
+	      (while (setq start (string-match re text start))
+		(setq text (replace-match su t t text 1)))))
+	  quotes))
+  text)
+
+(defvar org-screen-smart-quotes
+  '(("en" "“" "”" "‘" "’" "’")
+    ("fr" "«" "»" "‹" "›" "’")
+    ("de" "„" "“" "‚" "’" "’")))
+
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
 (defcustom org-export-with-archived-trees 'headline
   "Whether sub-trees with the ARCHIVE tag should be exported.
 
diff --git a/lisp/org.el b/lisp/org.el
index 8a141cf..72bf4b0 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5927,6 +5927,7 @@ needs to be inserted at a specific position in the
font-lock sequence.")
 	   ;; Specials
 	   '(org-do-latex-and-special-faces)
 	   '(org-fontify-entities)
+	   '(org-fontify-quotes)
 	   '(org-raise-scripts)
 	   ;; Code
 	   '(org-activate-code (1 'org-code t))
@@ -5948,6 +5949,55 @@ 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))
 
+(defvar org-smart-quotes nil)
+(defvar org-smart-quotes-replacements
+  '("«" "»" "‹" "›" "’"))
+;;  '("“" "”" "‘" "’" "’"))
+
+;; Nother idea, try this: like in original smart-quotes attempt.
+;; String all the regexps into one big regexp with \\| between them.
+;; Possibly have to parenthesize them but that's okay, since if
+;; each elt is in its own group, then those will be the odd-numbered groups
+;; and the inner group (of the actual quote) will be groups 2,4,6, etc.
+
+(defun splice-string (lst join)
+  (if (null (cdr lst)) (car lst)
+    (concat (car lst) join (splice-string (cdr lst) join))))
+
+(defun org-fontify-quotes (limit)
+  (require 'org-export)
+  (when org-smart-quotes
+    (let* ((start (point))
+	   k su
+	   (regexps
+	    (cdr 
+	     (assoc 'DEFAULT org-export-quotes-regexps)))
+	   (allreg (splice-string regexps "\\|"))
+	   (quotes (pairlis regexps org-smart-quotes-replacements)))
+      ;; (message "%s" allreg)
+      (catch 'match
+	(while (re-search-forward allreg limit t)
+	  (cond ((match-string 1)
+		 (setq k 1 su (nth 0 org-smart-quotes-replacements)))
+		((match-string 2)
+		 (setq k 2 su (nth 1 org-smart-quotes-replacements)))
+		((match-string 3)
+		 (setq k 3 su (nth 2 org-smart-quotes-replacements)))
+		((match-string 4)
+		 (setq k 4 su (nth 3 org-smart-quotes-replacements)))
+		((match-string 5)
+		 (setq k 5 su (nth 4 org-smart-quotes-replacements)))
+		;;(t
+		;; (message "????")))
+		)
+	  ;; (message "%s %s" k (match-data))
+	  (add-text-properties (match-beginning k) (match-end k)
+			       (list 'font-lock-fontified t
+				     'face 'org-warning))
+	  (compose-region (match-beginning k) (match-end k) su nil)
+	  (backward-char 1)
+	  (throw 'match t))))))
+
 (defun org-toggle-pretty-entities ()
   "Toggle the composition display of entities as UTF8 characters."
   (interactive)
-- 
1.7.7.6

  reply	other threads:[~2012-05-31  1:50 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-22  3:32 "Smart" quotes Mark E. Shoulson
2012-05-23 22:17 ` 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                 ` Mark Shoulson [this message]
2012-05-31 13:38                   ` (no subject) 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
  -- strict thread matches above, loose matches on Subject: below --
2019-02-04  3:40 (no subject) Lawrence Bottorff
2018-12-19 12:58 Emmanuel Charpentier
2018-10-20  9:02 stardiviner
2018-10-15  8:04 Nik Clayton
2018-10-17 13:20 ` Nicolas Goaziou
2019-09-15 21:06 ` Matt Price
2018-05-03 13:44 Arne Babenhauserheide
2018-05-03 14:29 ` Bastien
2018-05-03 21:02   ` Arne Babenhauserheide
2018-05-04  1:02     ` steen
2018-05-04  5:38   ` Michael Welle
2018-05-11 20:07 ` Nicolas Goaziou
2018-03-02 16:10 Joseph Vidal-Rosset
2016-11-01 16:10 John Kitchin
2016-09-19 16:38 John Brodie
2016-09-20 20:32 ` Nicolas Goaziou
2015-11-03 19:53 Fritz Kunze
2015-10-11 19:51 Shankar Rao
2015-09-04 14:51 Eduardo Mercovich
2015-09-04 15:25 ` thomas
2015-09-04 18:35   ` Eduardo Mercovich
2015-01-24 16:23 M.S.Khed Khed
2014-05-03  1:52 Ryan Moszynski
2014-05-03  3:01 ` William Henney
2014-05-03  3:22   ` William Henney
2014-01-30  0:03 Ken Okada
2014-01-30  0:15 ` Bastien
2014-01-30  0:22   ` John Hendy
2014-01-30  7:17     ` Ken Okada
2014-01-31  6:29       ` John Hendy
2014-01-31  7:11         ` Nick Dokos
2014-02-03 22:13           ` Marcin Borkowski
2013-11-06  6:13 Cecil Westerhof
2013-11-06  8:32 ` Bastien
2013-11-06  8:42 ` Bastien
     [not found]   ` <CAG-LmmDGaczy8pyeCTU6-YJ9oTBeEufqU6kC2PUb-U6ucexhZA@mail.gmail.com>
     [not found]     ` <87txfpaeli.fsf@bzg.ath.cx>
     [not found]       ` <CAG-LmmDFjqbuqfF1YJoeX6x_UdujK+0noeFcGSD15hs49Tbo=Q@mail.gmail.com>
2013-11-06 18:38         ` Cecil Westerhof
2013-10-11  7:14 "Recent items" Agenda view? Martin Beck
2013-10-11 20:35 ` Samuel Wales
2013-10-14  8:46   ` (no subject) Martin Beck
2013-03-07 20:37 [RFC] Org syntax (draft) Nicolas Goaziou
2013-03-08 10:39 ` was: " Andreas Röhler
2013-03-08 10:46   ` (no subject) Bastien
2013-03-08 10:59     ` Andreas Röhler
2013-03-08 11:05       ` Bastien
2013-03-08 11:18         ` Andreas Röhler
2013-03-08 11:23           ` Bastien
2013-03-08 13:00             ` Andreas Röhler
2013-03-08 13:12               ` Bastien
2013-03-08 15:22                 ` Andreas Röhler
2013-03-08 15:40                   ` Bastien
2013-03-08 20:39                     ` T.F. Torrey
2013-03-08 21:19                       ` Nicolas Goaziou
2013-03-08 21:57                         ` Suvayu Ali
2013-03-09 14:09                       ` Bastien
2013-03-10 22:40                         ` T.F. Torrey
2013-03-03  0:55 Vikas Rawal
2013-01-29  9:43 Martin Beck
2013-01-30 12:12 ` Bernt Hansen
2013-01-24 12:11 Herbert Sitz
2013-01-15 19:26 Rick Frankel
2012-11-11 15:36 Fabrice Popineau
2012-11-11 23:09 ` Nicolas Goaziou
2012-11-12  7:40   ` Fabrice Popineau
2012-11-07 18:50 Kevin Buchs
2012-09-29  7:30 Neuwirth Erich
2012-09-29  7:39 ` Bastien
2012-09-29  8:09   ` Achim Gratz
2012-09-29  9:12     ` Bastien
2012-09-29  9:52 ` Achim Gratz
2012-08-24 16:21 Feiming Chen
2012-05-11 20:56 Rick Frankel
2012-05-11 20:38 ` Eric Schulte
2012-05-11 22:43   ` Bernt Hansen
2012-05-17  6:23   ` Bastien
2012-01-23 12:00 Tom Regner
2012-01-23 16:34 ` Tom Regner
2012-01-23 20:31 ` Eric Schulte
2012-01-24  1:55   ` Tom Regner
2012-01-05 17:36 Ab Cd
2011-08-06  1:19 Vikas Rawal
2011-02-21 22:13 Vincent-Xavier JUMEL
2011-02-23 19:52 ` Bernt Hansen
2011-02-23 19:54 ` Bernt Hansen
2011-04-09  9:41   ` Vincent-Xavier JUMEL
2010-06-29 17:50 amscopub-mail
2009-09-18 12:35 Robin Green
2009-02-17 18:57 Matthew Lundin
2009-02-17 20:26 ` Carsten Dominik
2008-01-28 11:20 Dimitris Kapetanakis
2008-01-29  9:39 ` Bastien Guerry
2007-11-13 20:35 François Puitg
2007-10-20 10:33 Kevin Brubeck Unhammer
2007-10-21 22:20 ` Bastien
2006-05-25 10:43 Thomas Baumann
2006-05-25 12:49 ` Carsten Dominik

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=loom.20120531T025544-595@post.gmane.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).