emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] (no subject)


From: Nicolas Goaziou
Subject: Re: [O] (no subject)
Date: Thu, 31 May 2012 15:38:33 +0200

Hello,

Mark Shoulson <address@hidden> writes:

> +(defvar org-e-html-quote-replacements
> +  '(("fr" "« " " »" "‘" "’" "’")
> +    ("en" "“" "”" "‘" "’" "’")
> +    ("de" "„" "“" "‚" "‘" "’"))

A docstring will be required for this variable. It should be
a defcustom.

> +(defvar org-e-latex-quote-replacements
> +  '(("fr" "«~" "~»" "‹~" "~›" "/!")
> +    ("en" "((" "))" ".(" ")." "/")))

Ditto.

>  (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     "))))))

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) 
> +  (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=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")))

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 
> +       (cdr 
> +        (or 
> +         (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,

-- 
Nicolas Goaziou



reply via email to

[Prev in Thread] Current Thread [Next in Thread]