Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Emacs 组织模式包括忽略导出设置_Emacs_Org Mode - Fatal编程技术网

Emacs 组织模式包括忽略导出设置

Emacs 组织模式包括忽略导出设置,emacs,org-mode,Emacs,Org Mode,我有一个组织模式文档,其中包括其他组织模式文档。父文档应可导出为pdf格式,每个子文档也应可导出为pdf格式。以下是一个例子: index.org #+TITLE: Test Title * Intro This file must be exportable * Heading 1 #+INCLUDE: doc1.org :minlevel 2 :only-contents t #+TITLE: Inner title This file must be exportable

我有一个组织模式文档,其中包括其他组织模式文档。父文档应可导出为pdf格式,每个子文档也应可导出为pdf格式。以下是一个例子:

index.org

#+TITLE: Test Title

* Intro

  This file must be exportable

* Heading 1
  #+INCLUDE: doc1.org :minlevel 2 :only-contents t
#+TITLE: Inner title

This file must be exportable by itself aswell

* Heading 2

  And here is some text
doc1.org

#+TITLE: Test Title

* Intro

  This file must be exportable

* Heading 1
  #+INCLUDE: doc1.org :minlevel 2 :only-contents t
#+TITLE: Inner title

This file must be exportable by itself aswell

* Heading 2

  And here is some text
导出doc1.org将生成预期的:

但是导出index.org会产生(注意标题):


有没有办法抑制包含的组织文档的导出选项?

我通过覆盖一些组织模式elisp来修复这个问题。我把它放在我的
.emacs
中,现在一切正常了。当我有时间的时候,也许我会发布一个到组织模式的补丁

(defun fd--org-doc-begin ()
  "Skip all the initial export options"
  (save-excursion
    (goto-char (point-min))
    (while (and (or
                 (looking-at "[ \t]*#+")
                 (looking-at "[ \t]*$"))
                (progn (next-line) (< (point) (point-max))))
      (beginning-of-line))
    (point)))

;;; This was overriden from ox.el
(defun org-export--prepare-file-contents
    (file &optional lines ind minlevel id footnotes with-export-options)
  "Prepare contents of FILE for inclusion and return it as a string.

When optional argument LINES is a string specifying a range of
lines, include only those lines.

Optional argument IND, when non-nil, is an integer specifying the
global indentation of returned contents.  Since its purpose is to
allow an included file to stay in the same environment it was
created (e.g., a list item), it doesn't apply past the first
headline encountered.

Optional argument MINLEVEL, when non-nil, is an integer
specifying the level that any top-level headline in the included
file should have.

Optional argument ID is an integer that will be inserted before
each footnote definition and reference if FILE is an Org file.
This is useful to avoid conflicts when more than one Org file
with footnotes is included in a document.

Optional argument FOOTNOTES is a hash-table to store footnotes in
the included document.

Optional argument WITH-EXPORT-OPTIONS will stop this function
from ignoring export options at the beginning of the file."
  (with-temp-buffer
    (insert-file-contents file)
    (when (not with-export-options)
      (narrow-to-region (fd--org-doc-begin) (point-max)))
    (when lines
      (let* ((lines (split-string lines "-"))
         (lbeg (string-to-number (car lines)))
         (lend (string-to-number (cadr lines)))
         (beg (if (zerop lbeg) (point-min)
            (goto-char (point-min))
            (forward-line (1- lbeg))
            (point)))
         (end (if (zerop lend) (point-max)
            (goto-char (point-min))
            (forward-line (1- lend))
            (point))))
    (narrow-to-region beg end)))
    ;; Remove blank lines at beginning and end of contents.  The logic
    ;; behind that removal is that blank lines around include keyword
    ;; override blank lines in included file.
    (goto-char (point-min))
    (org-skip-whitespace)
    (beginning-of-line)
    (delete-region (point-min) (point))
    (goto-char (point-max))
    (skip-chars-backward " \r\t\n")
    (forward-line)
    (delete-region (point) (point-max))
    ;; If IND is set, preserve indentation of include keyword until
    ;; the first headline encountered.
    (when (and ind (> ind 0))
      (unless (eq major-mode 'org-mode)
    (let ((org-inhibit-startup t)) (org-mode)))
      (goto-char (point-min))
      (let ((ind-str (make-string ind ?\s)))
    (while (not (or (eobp) (looking-at org-outline-regexp-bol)))
      ;; Do not move footnote definitions out of column 0.
      (unless (and (looking-at org-footnote-definition-re)
               (eq (org-element-type (org-element-at-point))
               'footnote-definition))
        (insert ind-str))
      (forward-line))))
    ;; When MINLEVEL is specified, compute minimal level for headlines
    ;; in the file (CUR-MIN), and remove stars to each headline so
    ;; that headlines with minimal level have a level of MINLEVEL.
    (when minlevel
      (unless (eq major-mode 'org-mode)
    (let ((org-inhibit-startup t)) (org-mode)))
      (org-with-limited-levels
       (let ((levels (org-map-entries
              (lambda () (org-reduced-level (org-current-level))))))
     (when levels
       (let ((offset (- minlevel (apply #'min levels))))
         (unless (zerop offset)
           (when org-odd-levels-only (setq offset (* offset 2)))
           ;; Only change stars, don't bother moving whole
           ;; sections.
           (org-map-entries
        (lambda ()
          (if (< offset 0) (delete-char (abs offset))
            (insert (make-string offset ?*)))))))))))
    ;; Append ID to all footnote references and definitions, so they
    ;; become file specific and cannot collide with footnotes in other
    ;; included files.  Further, collect relevant footnote definitions
    ;; outside of LINES, in order to reintroduce them later.
    (when id
      (let ((marker-min (point-min-marker))
        (marker-max (point-max-marker))
        (get-new-label
         (lambda (label)
           ;; Generate new label from LABEL by prefixing it with
           ;; "-ID-".
           (format "-%d-%s" id label)))
        (set-new-label
         (lambda (f old new)
           ;; Replace OLD label with NEW in footnote F.
           (save-excursion
         (goto-char (+ (org-element-property :begin f) 4))
         (looking-at (regexp-quote old))
         (replace-match new))))
        (seen-alist))
    (goto-char (point-min))
    (while (re-search-forward org-footnote-re nil t)
      (let ((footnote (save-excursion
                (backward-char)
                (org-element-context))))
        (when (memq (org-element-type footnote)
            '(footnote-definition footnote-reference))
          (let* ((label (org-element-property :label footnote)))
        ;; Update the footnote-reference at point and collect
        ;; the new label, which is only used for footnotes
        ;; outsides LINES.
        (when label
          (let ((seen (cdr (assoc label seen-alist))))
            (if seen (funcall set-new-label footnote label seen)
              (let ((new (funcall get-new-label label)))
            (push (cons label new) seen-alist)
            (org-with-wide-buffer
             (let* ((def (org-footnote-get-definition label))
                (beg (nth 1 def)))
               (when (and def
                      (or (< beg marker-min)
                      (>= beg marker-max)))
                 ;; Store since footnote-definition is
                 ;; outside of LINES.
                 (puthash new
                      (org-element-normalize-string (nth 3 def))
                      footnotes))))
            (funcall set-new-label footnote label new)))))))))
    (set-marker marker-min nil)
    (set-marker marker-max nil)))
    (org-element-normalize-string (buffer-string))))
(defun fd——组织文档开始()
“跳过所有初始导出选项”
(省去远足
(转到字符(最小点))
(同时)和(或)
(查看“[\t]*#+”)
(查看“[\t]*$”)
(程序(下一行)(<(点)(最大点)))
(行首)
(点))
;;; 这是从ox.el重写的
(defun组织导出--准备文件内容)
(带导出选项的级别id脚注的文件行和可选行)
“准备要包含的文件内容,并将其作为字符串返回。
当可选参数行是指定参数范围的字符串时
行,仅包括那些行。
可选参数IND(非nil时)是一个整数,用于指定
返回内容的全局缩进。因为其目的是
允许包含的文件保留在原来的环境中
创建(例如,列表项)后,它不适用于第一个
遇到标题。
可选参数MINLEVEL在非nil时为整数
指定包含在列表中的任何顶级标题的级别
文件应该有。
可选参数ID是将在之前插入的整数
如果文件是组织文件,则每个脚注定义和参考。
这有助于避免多个组织文件发生冲突
在文件中包括脚注。
可选参数脚注是用于存储脚注的哈希表
所包括的文件。
带有-EXPORT-OPTIONS的可选参数将停止此函数
从忽略文件开头的导出选项开始。“
(带临时缓冲器)
(插入文件内容文件)
(何时(不带导出选项)
(缩小到区域(fd--组织文档开始)(最大点)))
(当你排队时)
(let*((行(拆分字符串行“-”)
(lbeg(字符串到数字(轿厢线)))
(借出(字符串到数字(cadr行)))
(beg)(如果(零位lbeg)(最低点)
(转到字符(最小点))
(前线(1-lbeg))
(点))
(结束(如果为零)(最大点)
(转到字符(最小点))
(远期(1-贷款))
(点)
(狭窄到末端)
删除内容开头和结尾的空行。逻辑
删除的背后是include关键字周围的空行
;;覆盖包含文件中的空行。
(转到字符(最小点))
(组织跳过空白)
(行首)
(删除区域(点最小值)(点))
(转到字符(最大点))
(向后跳过字符“\r\t\n”)
(前线)
(删除区域(点)(最大点))
;如果设置了IND,则保留include关键字的缩进,直到
遇到的第一个标题。
(当(和ind(>ind0))
(除非(eq专业模式“组织模式”)
(让((组织禁止启动t))(组织模式)))
(转到字符(最小点))
(let((ind str(make string ind?\s)))
(而(不是(或(eobp)(查看组织大纲regexp bol)))
;不要将脚注定义移出第0列。
(除非(和(参见组织脚注定义)
(eq(组织要素类型(点组织要素))
(脚注定义)
(插入工业街)
(前线)
;;指定MINLEVEL时,计算标题的最小级别
;;在文件(CUR-MIN)中,删除每个标题的星号,以便
最低级别的标题具有最低级别。
(当水平时)
(除非(eq专业模式“组织模式”)
(让((组织禁止启动t))(组织模式)))
(限制级别的组织)
(let((级别)(组织图条目
(lambda()(组织降低级别(组织当前级别()()())))
(当水平
(让((偏移量(-minlevel(应用#'minlevels)))
(除非(零点偏移)
(仅当组织奇数级别时(setq偏移量(*偏移量2)))
只换星星,不必费心移动整颗星星
;部分。
(组织)地图条目
(lambda()
(如果(