From mboxrd@z Thu Jan 1 00:00:00 1970 From: pierre.techoueyres@free.fr (Pierre =?utf-8?Q?T=C3=A9choueyres?=) Subject: Re: [PATCH] Add new keyword :coding for #+include directive Date: Wed, 25 Apr 2018 00:57:09 +0200 Message-ID: <874lk01ad6.fsf@killashandra.ballybran.fr> References: <87tvsbx72g.fsf@killashandra.ballybran.fr> <87in8qyh3t.fsf@killashandra.ballybran.fr> <874lkakz58.fsf@nicolasgoaziou.fr> <87muy0b4kw.fsf@killashandra.ballybran.fr> <87in8lh3xk.fsf@killashandra.ballybran.fr> <87zi1uqkta.fsf@nicolasgoaziou.fr> <87in8hd7xe.fsf@killashandra.ballybran.fr> <87zi1sl0yq.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fB6s9-0002Zc-5d for emacs-orgmode@gnu.org; Tue, 24 Apr 2018 18:57:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fB6s5-0002Iv-7B for emacs-orgmode@gnu.org; Tue, 24 Apr 2018 18:57:17 -0400 Received: from smtp4-g21.free.fr ([212.27.42.4]:43140) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fB6s4-0002Hj-SA for emacs-orgmode@gnu.org; Tue, 24 Apr 2018 18:57:13 -0400 In-Reply-To: <87zi1sl0yq.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Tue, 24 Apr 2018 23:59:57 +0200") 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" To: Nicolas Goaziou Cc: org-mode --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, Nicolas Goaziou writes: > Hello, > > pierre.techoueyres@free.fr (Pierre T=C3=A9choueyres) writes: > >> I think I've corrected all points. You'll find new versions attached. > > Thank you. > >> Would you mind consider to include the patch for the detection of >> encoding with the #+include keyword in 9.2 release ? > > This patch is still missing some small parts for proper integration, > namely documentation, and, if possible, a couple of tests. Besides, 9.2 > branch is supposedly frozen. I argree for the documentation and tests (but I have to admit I don't know how to add them). > Granted, it doesn't seem too harmful, but is there any strong reason to > integrate it in Org 9.2 (assuming documentation is ready)? I think I wasn't clear enough : I had hope you will only include the part which correct the decoding of include keyword, not the whole two patchs. I think the former is simply a bug fixes.=20 > >> + (coding >> + (intern (or (and (string-match >> + >> ":coding[[:space:]]+\\_<\\(\\(?:\\sw\\|\\$\\|&\\|\\*\\|\\+\\|-\\|_\\|<\\= |>\\)+\\)\\_>" >> value) >> + (prog1 (match-string 1 value) >> + (setq value (replace-match "" nil nil value)))) >> + (symbol-name coding-system-for-read)))) > > I suggested a refactoring that you didn't integrate: it seems wasteful > to call `intern' on the return value of `symbol-name'. > > Besides, my suggestion about the regexp was wrong. We shouldn't make the > syntax foolproof. I think > > ":coding +\\(\\S-+\\)" > > is enough actually. Sorry about sending you in the wrong track. > > Regards, Here is a new amended patch. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-Add-new-keyword-coding-for-include-directive.patch Content-Transfer-Encoding: quoted-printable Content-Description: include-new-directive >From bb9d154ba06d2fd3608bf6877c0b765a932b38e7 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Pierre=3D20T=3DC3=3DA9choueyres?=3D Date: Sat, 21 Apr 2018 00:31:10 +0200 Subject: [PATCH] Add new keyword :coding for #+include directive * lisp/ox.el (org-export-expand-include-keyword): Add new keyword `:coding' for specify the file encoding whith the `#+include:' directive. This allow to use somting like : #+include: "./myfile" :coding cp850-dos when your Org file is encoded in utf-8 for example. --- etc/ORG-NEWS | 7 ++++ lisp/ox.el | 121 +++++++++++++++++++++++++++++++------------------------= ---- 2 files changed, 71 insertions(+), 57 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index abebe08fe..99350ee84 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -121,6 +121,13 @@ now sort according to the locale=E2=80=99s collation r= ules instead of by code-point. =20 ** New features +*** New keyword for ~#+include:~ directive +Add =3D:coding codign-system=3D keyword to allow include of files from +different codign system than the main Org file. +For example: +#+begin_example +,#+INCLUDE: "myfile.cmd" src cmd :coding cp850-dos +#+end_example *** Add ~:results link~ support for Babel =20 With this output format, create a link to the file specified in diff --git a/lisp/ox.el b/lisp/ox.el index 5a83ae01d..dd454ef42 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3298,6 +3298,12 @@ storing and resolving footnotes. It is created auto= matically." (org-unbracket-string "\"" "\"" matched) dir))) (setq value (replace-match "" nil nil value))))) + (coding + (or (and (string-match + ":coding +\\_<\\(\\S-+\\)\\_>" value) + (prog1 (intern (match-string 1 value)) + (setq value (replace-match "" nil nil value)))) + coding-system-for-read)) (only-contents (and (string-match ":only-contents *\\([^: \r\t\n]\\S-*\\)?" value) @@ -3331,65 +3337,66 @@ storing and resolving footnotes. It is created aut= omatically." (match-string 1 value)))) ;; Remove keyword. (delete-region (point) (line-beginning-position 2)) - (cond - ((not file) nil) - ((not (file-readable-p file)) - (error "Cannot include file %s" file)) - ;; Check if files has already been parsed. Look after - ;; inclusion lines too, as different parts of the same - ;; file can be included too. - ((member (list file lines) included) - (error "Recursive file inclusion: %s" file)) - (t + (let ((coding-system-for-read coding)) (cond - ((eq env 'literal) - (insert - (let ((ind-str (make-string ind ?\s)) - (arg-str (if (stringp args) (format " %s" args) "")) - (contents - (org-escape-code-in-string - (org-export--prepare-file-contents file lines)))) - (format "%s#+BEGIN_%s%s\n%s%s#+END_%s\n" - ind-str block arg-str contents ind-str block)))) - ((stringp block) - (insert - (let ((ind-str (make-string ind ?\s)) - (contents - (org-export--prepare-file-contents file lines))) - (format "%s#+BEGIN_%s\n%s%s#+END_%s\n" - ind-str block contents ind-str block)))) + ((not file) nil) + ((not (file-readable-p file)) + (error "Cannot include file %s" file)) + ;; Check if files has already been parsed. Look after + ;; inclusion lines too, as different parts of the same + ;; file can be included too. + ((member (list file lines) included) + (error "Recursive file inclusion: %s" file)) (t - (insert - (with-temp-buffer - (let ((org-inhibit-startup t) - (lines - (if location - (org-export--inclusion-absolute-lines - file location only-contents lines) - lines))) - (org-mode) - (insert - (org-export--prepare-file-contents - file lines ind minlevel - (or (gethash file file-prefix) - (puthash file - (cl-incf current-prefix) - file-prefix)) - footnotes - includer-file))) - (org-export-expand-include-keyword - (cons (list file lines) included) - (file-name-directory file) - footnotes) - (buffer-string))))) - ;; Expand footnotes after all files have been - ;; included. Footnotes are stored at end of buffer. - (unless included - (org-with-wide-buffer - (goto-char (point-max)) - (maphash (lambda (k v) - (insert (format "\n[fn:%s] %s\n" k v))) - footnotes)))))))))))) + (cond + ((eq env 'literal) + (insert + (let ((ind-str (make-string ind ?\s)) + (arg-str (if (stringp args) (format " %s" args) "")) + (contents + (org-escape-code-in-string + (org-export--prepare-file-contents file lines)))) + (format "%s#+BEGIN_%s%s\n%s%s#+END_%s\n" + ind-str block arg-str contents ind-str block)))) + ((stringp block) + (insert + (let ((ind-str (make-string ind ?\s)) + (contents + (org-export--prepare-file-contents file lines))) + (format "%s#+BEGIN_%s\n%s%s#+END_%s\n" + ind-str block contents ind-str block)))) + (t + (insert + (with-temp-buffer + (let ((org-inhibit-startup t) + (lines + (if location + (org-export--inclusion-absolute-lines + file location only-contents lines) + lines))) + (org-mode) + (insert + (org-export--prepare-file-contents + file lines ind minlevel + (or (gethash file file-prefix) + (puthash file + (cl-incf current-prefix) + file-prefix)) + footnotes + includer-file))) + (org-export-expand-include-keyword + (cons (list file lines) included) + (file-name-directory file) + footnotes) + (buffer-string))))) + ;; Expand footnotes after all files have been + ;; included. Footnotes are stored at end of buffer. + (unless included + (org-with-wide-buffer + (goto-char (point-max)) + (maphash (lambda (k v) + (insert (format "\n[fn:%s] %s\n" k v))) + footnotes))))))))))))) =20 (defun org-export--inclusion-absolute-lines (file location only-contents l= ines) "Resolve absolute lines for an included file with file-link. --=20 2.14.3 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Regards, --=20 Pierre T=C3=A9choueyres --=-=-=--