From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: (no subject) Date: Thu, 31 May 2012 15:38:33 +0200 Message-ID: <87r4u031ye.fsf@gmail.com> References: <4FBB08CA.5060705@kli.org> <87d35u8rvk.fsf@gmail.com> <4FBDA56E.5030901@kli.org> <87zk8w6v4q.fsf@gmail.com> <4FC00CE0.6060308@kli.org> <87r4u75tg9.fsf@gmail.com> <4FC426AC.2030109@kli.org> <87ehq227ky.fsf@gmail.com> <4FC56F1B.5040201@kli.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:57550) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sa5dJ-0000fy-Ci for emacs-orgmode@gnu.org; Thu, 31 May 2012 09:41:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sa5d7-0007lK-2r for emacs-orgmode@gnu.org; Thu, 31 May 2012 09:41:44 -0400 Received: from mail-wi0-f171.google.com ([209.85.212.171]:56903) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sa5d6-0007gV-Mn for emacs-orgmode@gnu.org; Thu, 31 May 2012 09:41:32 -0400 Received: by wibhm14 with SMTP id hm14so3679278wib.12 for ; Thu, 31 May 2012 06:41:30 -0700 (PDT) In-Reply-To: (Mark Shoulson's message of "Thu, 31 May 2012 01:50:39 +0000 (UTC)") 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: Mark Shoulson Cc: emacs-orgmode@gnu.org Hello, Mark Shoulson writes: > +(defvar org-e-html-quote-replacements > + '(("fr" "=C2=AB=C2=A0" "=C2=A0=C2=BB" "=E2=80=98" "=E2=80=99" "=E2=80= =99") > + ("en" "=E2=80=9C" "=E2=80=9D" "=E2=80=98" "=E2=80=99" "=E2=80=99") > + ("de" "=E2=80=9E" "=E2=80=9C" "=E2=80=9A" "=E2=80=98" "=E2=80=99")) A docstring will be required for this variable. It should be a defcustom. > +(defvar org-e-latex-quote-replacements > + '(("fr" "=C2=AB~" "~=C2=BB" "=E2=80=B9~" "~=E2=80=BA" "/!") > + ("en" "((" "))" ".(" ")." "/"))) Ditto. > (defcustom org-e-latex-quotes > '(("fr" > ("\\(\\s-\\|[[(]\\|^\\)\"" . "=C2=AB~") > @@ -699,25 +703,22 @@ during latex export it will output > "Alist for quotes to use when converting english double-quotes. >=20=20 > 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. >=20=20 > 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 ")))))) The docstring is not valid. It's now an an alist whose key is the language code and the value is a list of strings, not cons cells. > +(defun org-e-latex--quotation-marks (text info)=20 > + (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) Use directly `org-e-latex-quote-replacements' in code then. > +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > +;; Probably a defcustom eventually. > + > +;; Each element of this consists of: car=3Dlanguage code, cdr=3Dlist 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=20 > + "\\(?:\\s-\\|[[(]\\|^\\)\\(\"\\)\\w"=20 > + "\\(?:\\S-\\)\\(\"\\)\\s-"=20 > + "\\(?:\\s-\\|(\\|^\\)\\('\\)\\w" > + "\\w\\('\\)\\(?:\\s-\\|\\s.\\|$\\)" > + "\\w\\('\\)\\w"))) I'm not sure this variable can be used for both the buffer and the export engine. Export back-ends will only see chunks of the paragraph. For example, in the following text, He crossed the Rubicon and said: "/Alea jacta est./" Plain text translators will see three strings: 1. "He crossed the Rubicon and said: \"" 2. "Alea jacta est." 3. "\"" In case 1, you have an opening quote with nothing after it. In case 3, you have a closing quote with nothing before or after it. Plain regexps can't help here. The only solution in can think of is to do quote substitutions in paragraphs within the parse tree before they reach the translators (i.e. with `org-export-filter-parse-tree-functions'). That's the only way to know if "\"" is an opening or a closing quote, for example. The current approach won't work. > +;; 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." Please document each argument in the docstring. > + (let* ((start 0) > + (regexps=20 > + (cdr=20 > + (or=20 > + (assoc (plist-get info :language) > + org-export-quotes-regexps) > + (assoc 'DEFAULT org-export-quotes-regexps)))) Use `assq' instead of `assoc' in the second case. > + (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))))) Use `replace-regexp-in-string' instead. (replace-regexp-in-string (car p) (cdr p) text t t 1) > + quotes)) > + text) Regards, --=20 Nicolas Goaziou