ソースを参照

Column view: Capture also from locations in other files.

The dynamic block capturing column view has an :id parameter that does
select from where the column view should be captured.  The routine
searching for this entry so far only searched the current file, now it
uses the full ID API to find the entry also in another file.

Furthermore, a value "file:path/to/file.org" will capture the global
column view of that file.

Report by Francois Lagarde.
Carsten Dominik 16 年 前
コミット
2deee3e6e4
7 ファイル変更128 行追加37 行削除
  1. 14 0
      ORGWEBPAGE/Changes.org
  2. 6 0
      doc/ChangeLog
  3. 3 1
      doc/org.texi
  4. 11 0
      lisp/ChangeLog
  5. 52 19
      lisp/org-colview-xemacs.el
  6. 39 17
      lisp/org-colview.el
  7. 3 0
      lisp/org-id.el

+ 14 - 0
ORGWEBPAGE/Changes.org

@@ -10,6 +10,20 @@
 #+LINK_UP: index.html
 #+LINK_HOME: http://orgmode.org
 
+* Version 6.17 (in preparation)
+
+** Details
+
+*** Capture column view into a different file.
+
+    The :id parameter for the dynamic block capturing column view
+    can now truly be an ID that will also be found in a
+    different file.  Also, it can be like =file:path/to/file=, to
+    capture the global column view from a different file.
+
+    Thanks to Francois Lagarde for his report that IDs outside
+    the current file would not work.
+
 * Version 6.16
   :PROPERTIES:
   :VISIBILITY: content

+ 6 - 0
doc/ChangeLog

@@ -1,3 +1,9 @@
+2008-12-22  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org.texi (Capturing column view): Document
+	"file:path/to/file.org" as an allowed value for the ID property of
+	a dynamic block copying column view.
+
 2008-12-19  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org.texi (References): Document special last-row references.

+ 3 - 1
doc/org.texi

@@ -4216,7 +4216,9 @@ capture, you can use 3 values:
 @example
 local     @r{use the tree in which the capture block is located}
 global    @r{make a global view, including all headings in the file}
-"label"   @r{call column view in the tree that has an @code{:ID:}}
+"file:path-to-file"
+          @r{run column view at the top of this file}
+"ID"      @r{call column view in the tree that has an @code{:ID:}}
           @r{property with the value @i{label}.  You can use}
           @r{@kbd{M-x org-id-copy} to create a globally unique ID for}
           @r{the current entry and copy it to the kill-ring.}

+ 11 - 0
lisp/ChangeLog

@@ -1,3 +1,14 @@
+2008-12-22  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org-id.el (org-id-find): Allow the ID to be a symbol or a
+	number, by converting these to a string.
+
+	* org-colview.el (org-dblock-write:columnview): Allow ID to be
+	located in a different file.
+
+	* org-colview-xemacs.el (org-dblock-write:columnview): Copy from
+	org-colview.el.
+
 2008-12-21  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org.el (org-completion-use-ido): Enhance docstring of

+ 52 - 19
lisp/org-colview-xemacs.el

@@ -1297,10 +1297,12 @@ PARAMS is a property list of parameters:
 
 :width    enforce same column widths with <N> specifiers.
 :id       the :ID: property of the entry where the columns view
-          should be built, as a string.  When `local', call locally.
+          should be built.  When the symbol `local', call locally.
           When `global' call column view with the cursor at the beginning
           of the buffer (usually this means that the whole buffer switches
-          to column view).
+          to column view).  When \"file:path/to/file.org\", invoke column
+          view at the start of that file.  Otherwise, the ID is located
+          using `org-id-find'.
 :hlines   When t, insert a hline before each item.  When a number, insert
           a hline before each level <= that number.
 :vlines   When t, make each column a colgroup to enforce vertical lines.
@@ -1311,21 +1313,40 @@ PARAMS is a property list of parameters:
 	(hlines (plist-get params :hlines))
 	(vlines (plist-get params :vlines))
 	(maxlevel (plist-get params :maxlevel))
+	(content-lines (org-split-string (plist-get params :content) "\n"))
 	(skip-empty-rows (plist-get params :skip-empty-rows))
-	tbl id idpos nfields tmp)
-    (save-excursion
-      (save-restriction
-	(when (setq id (plist-get params :id))
-	  (cond ((not id) nil)
-		((eq id 'global) (goto-char (point-min)))
-		((eq id 'local)  nil)
-		((setq idpos (org-find-entry-with-id id))
-		 (goto-char idpos))
-		(t (error "Cannot find entry with :ID: %s" id))))
-	(org-columns)
-	(setq tbl (org-columns-capture-view maxlevel skip-empty-rows))
-	(setq nfields (length (car tbl)))
-	(org-columns-quit)))
+	tbl id idpos nfields tmp recalc line
+	id-as-string view-file view-pos)
+    (when (setq id (plist-get params :id))
+      (setq id-as-string (cond ((numberp id) (number-to-string id))
+			       ((symbolp id) (symbol-name id))
+			       ((stringp id) id)
+			       (t "")))
+      (cond ((not id) nil)
+	    ((eq id 'global) (setq view-pos (point-min)))
+	    ((eq id 'local))
+	    ((string-match "^file:\\(.*\\)" id-as-string)
+	     (setq view-file (match-string 1 id-as-string)
+		   view-pos 1)
+	     (unless (file-exists-p view-file)
+	       (error "No such file: \"%s\"" id-as-string)))
+	    ((setq idpos (org-find-entry-with-id id))
+	     (setq view-pos idpos))
+	    ((setq idpos (org-id-find id))
+	     (setq view-file (car idpos))
+	     (setq view-pos (cdr idpos)))
+	    (t (error "Cannot find entry with :ID: %s" id))))
+    (with-current-buffer (if view-file
+			     (get-file-buffer view-file)
+			   (current-buffer))
+      (save-excursion
+	(save-restriction
+	  (widen)
+	  (goto-char (or view-pos (point)))
+	  (org-columns)
+	  (setq tbl (org-columns-capture-view maxlevel skip-empty-rows))
+	  (setq nfields (length (car tbl)))
+	  (org-columns-quit))))
     (goto-char pos)
     (move-marker pos nil)
     (when tbl
@@ -1337,7 +1358,9 @@ PARAMS is a property list of parameters:
 	    (if (string-match "\\` *\\(\\*+\\)" (caar tbl))
 		(if (and (not (eq (car tmp) 'hline))
 			 (or (eq hlines t)
-			     (and (numberp hlines) (<= (- (match-end 1) (match-beginning 1)) hlines))))
+			     (and (numberp hlines)
+				  (<= (- (match-end 1) (match-beginning 1))
+				      hlines))))
 		    (push 'hline tmp)))
 	    (push (pop tbl) tmp)))
 	(setq tbl (nreverse tmp)))
@@ -1347,12 +1370,22 @@ PARAMS is a property list of parameters:
 			  tbl))
 	(setq tbl (append tbl (list (cons "/" (make-list nfields "<>"))))))
       (setq pos (point))
+      (when content-lines
+	(while (string-match "^#" (car content-lines))
+	  (insert (pop content-lines) "\n")))
       (insert (org-listtable-to-string tbl))
       (when (plist-get params :width)
 	(insert "\n|" (mapconcat (lambda (x) (format "<%d>" (max 3 x)))
 				 org-columns-current-widths "|")))
-      (goto-char pos)
-      (org-table-align))))
+      (while (setq line (pop content-lines))
+	(when (string-match "^#" line)
+	  (insert "\n" line)
+	  (when (string-match "^#\\+TBLFM" line)
+	    (setq recalc t))))
+      (if recalc
+	  (progn (goto-char pos) (org-table-recalculate 'all))
+	(goto-char pos)
+	(org-table-align)))))
 
 (defun org-listtable-to-string (tbl)
   "Convert a listtable TBL to a string that contains the Org-mode table.

+ 39 - 17
lisp/org-colview.el

@@ -1067,10 +1067,12 @@ PARAMS is a property list of parameters:
 
 :width    enforce same column widths with <N> specifiers.
 :id       the :ID: property of the entry where the columns view
-          should be built, as a string.  When `local', call locally.
+          should be built.  When the symbol `local', call locally.
           When `global' call column view with the cursor at the beginning
           of the buffer (usually this means that the whole buffer switches
-          to column view).
+          to column view).  When \"file:path/to/file.org\", invoke column
+          view at the start of that file.  Otherwise, the ID is located
+          using `org-id-find'.
 :hlines   When t, insert a hline before each item.  When a number, insert
           a hline before each level <= that number.
 :vlines   When t, make each column a colgroup to enforce vertical lines.
@@ -1083,20 +1085,38 @@ PARAMS is a property list of parameters:
 	(maxlevel (plist-get params :maxlevel))
 	(content-lines (org-split-string (plist-get params :content) "\n"))
 	(skip-empty-rows (plist-get params :skip-empty-rows))
-	tbl id idpos nfields tmp recalc line)
-    (save-excursion
-      (save-restriction
-	(when (setq id (plist-get params :id))
-	  (cond ((not id) nil)
-		((eq id 'global) (goto-char (point-min)))
-		((eq id 'local)  nil)
-		((setq idpos (org-find-entry-with-id id))
-		 (goto-char idpos))
-		(t (error "Cannot find entry with :ID: %s" id))))
-	(org-columns)
-	(setq tbl (org-columns-capture-view maxlevel skip-empty-rows))
-	(setq nfields (length (car tbl)))
-	(org-columns-quit)))
+	tbl id idpos nfields tmp recalc line
+	id-as-string view-file view-pos)
+    (when (setq id (plist-get params :id))
+      (setq id-as-string (cond ((numberp id) (number-to-string id))
+			       ((symbolp id) (symbol-name id))
+			       ((stringp id) id)
+			       (t "")))
+      (cond ((not id) nil)
+	    ((eq id 'global) (setq view-pos (point-min)))
+	    ((eq id 'local))
+	    ((string-match "^file:\\(.*\\)" id-as-string)
+	     (setq view-file (match-string 1 id-as-string)
+		   view-pos 1)
+	     (unless (file-exists-p view-file)
+	       (error "No such file: \"%s\"" id-as-string)))
+	    ((setq idpos (org-find-entry-with-id id))
+	     (setq view-pos idpos))
+	    ((setq idpos (org-id-find id))
+	     (setq view-file (car idpos))
+	     (setq view-pos (cdr idpos)))
+	    (t (error "Cannot find entry with :ID: %s" id))))
+    (with-current-buffer (if view-file
+			     (get-file-buffer view-file)
+			   (current-buffer))
+      (save-excursion
+	(save-restriction
+	  (widen)
+	  (goto-char (or view-pos (point)))
+	  (org-columns)
+	  (setq tbl (org-columns-capture-view maxlevel skip-empty-rows))
+	  (setq nfields (length (car tbl)))
+	  (org-columns-quit))))
     (goto-char pos)
     (move-marker pos nil)
     (when tbl
@@ -1108,7 +1128,9 @@ PARAMS is a property list of parameters:
 	    (if (string-match "\\` *\\(\\*+\\)" (caar tbl))
 		(if (and (not (eq (car tmp) 'hline))
 			 (or (eq hlines t)
-			     (and (numberp hlines) (<= (- (match-end 1) (match-beginning 1)) hlines))))
+			     (and (numberp hlines)
+				  (<= (- (match-end 1) (match-beginning 1))
+				      hlines))))
 		    (push 'hline tmp)))
 	    (push (pop tbl) tmp)))
 	(setq tbl (nreverse tmp)))

+ 3 - 0
lisp/org-id.el

@@ -262,6 +262,9 @@ Move the cursor to that entry in that buffer."
 The return value is a cons cell (file-name . position), or nil
 if there is no entry with that ID.
 With optional argument MARKERP, return the position as a new marker."
+  (cond
+   ((symbolp id) (setq id (symbol-name id)))
+   ((numberp id) (setq id (number-to-string id))))
   (let ((file (org-id-find-id-file id))
 	org-agenda-new-buffers where)
     (when file