From 2deee3e6e4266426ab34f30191e653f2bae39ac4 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Mon, 22 Dec 2008 08:13:20 +0100 Subject: [PATCH] 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. --- ORGWEBPAGE/Changes.org | 14 +++++++++ doc/ChangeLog | 6 ++++ doc/org.texi | 4 ++- lisp/ChangeLog | 11 +++++++ lisp/org-colview-xemacs.el | 71 +++++++++++++++++++++++++++++++++------------- lisp/org-colview.el | 56 +++++++++++++++++++++++++----------- lisp/org-id.el | 3 ++ 7 files changed, 128 insertions(+), 37 deletions(-) diff --git a/ORGWEBPAGE/Changes.org b/ORGWEBPAGE/Changes.org index 815e73d0f..79785db21 100644 --- a/ORGWEBPAGE/Changes.org +++ b/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 diff --git a/doc/ChangeLog b/doc/ChangeLog index a36a20cdb..91496c871 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2008-12-22 Carsten Dominik + + * 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 * org.texi (References): Document special last-row references. diff --git a/doc/org.texi b/doc/org.texi index b40f47f24..e7fe15517 100644 --- a/doc/org.texi +++ b/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.} diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0edcca8e6..8c8aa030d 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2008-12-22 Carsten Dominik + + * 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 * org.el (org-completion-use-ido): Enhance docstring of diff --git a/lisp/org-colview-xemacs.el b/lisp/org-colview-xemacs.el index ce70dd81e..7ec9d59f5 100644 --- a/lisp/org-colview-xemacs.el +++ b/lisp/org-colview-xemacs.el @@ -1297,10 +1297,12 @@ PARAMS is a property list of parameters: :width enforce same column widths with 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. diff --git a/lisp/org-colview.el b/lisp/org-colview.el index e4df62c65..e38b8b63f 100644 --- a/lisp/org-colview.el +++ b/lisp/org-colview.el @@ -1067,10 +1067,12 @@ PARAMS is a property list of parameters: :width enforce same column widths with 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))) diff --git a/lisp/org-id.el b/lisp/org-id.el index ddee3b187..6efa8e502 100644 --- a/lisp/org-id.el +++ b/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 -- 2.11.4.GIT