How can I collapse all records older than 3 months in the org-mode emacs log file?

I have a large log file with date entries like this:

  [2011-06-23 Thu]

 some text

 [2011-06-22 Wed]

 some more text

 [... 12MB of text later ...]

 [2000-01-01 Sat]

 first entry

I would like to be able to configure org-mode so that only the last 3 months are displayed, while old records are collapsed and only expand when I need to. Is there a way to configure this automatically so that every new day next time resets the record for 3 months + 1 day?

As now, it is impossible for me to use, because downloading a document takes more than a minute.

+3
source share
4 answers

With 12 MB of text that got a huge amount of date input headers, so I would suggest that narrowing the buffer might still be a good way.

I am new to org-mode, so I may miss the easier way to achieve this, but the following will automatically narrow the buffer to entries made three months before the current date.

(defvar my-org-journal "/path/to/file.org") (add-hook 'org-mode-hook 'my-org-mode-hook) (defun my-org-mode-hook () (when (equal (expand-file-name (buffer-file-name)) (expand-file-name my-org-journal)) (my-org-narrow-to-month-of-entries))) (defun my-org-narrow-to-month-of-entries () "Narrow buffer to entries within the last three months." (interactive) (let ((minimum-date (with-temp-buffer (progn (org-insert-time-stamp (current-time) nil t) (org-timestamp-change -3 'month) (buffer-substring-no-properties (point-min) (point-max)))))) (save-excursion (while (search-forward-regexp org-tsr-regexp-both nil t) (let ((end (point))) (backward-sexp) (let ((datestamp (buffer-substring-no-properties (point) end))) (if (string< datestamp minimum-date) (narrow-to-region (point-min) (point)) (forward-sexp)))))))) 

And, of course, Cx n w to expand the buffer again to see all the records.

If you want to apply this based on a local variable, and not by file name, you can use this approach:

 (defvar my-org-narrow-to-month-of-entries nil) (add-hook 'org-mode-hook 'my-org-mode-hook) (defun my-org-mode-hook () (add-hook 'hack-local-variables-hook (lambda () (when my-org-narrow-to-month-of-entries (my-org-narrow-to-month-of-entries))) nil t)) 

with the following at the end of the file:

 ;;; Local Variables: ;;; my-org-narrow-to-month-of-entries: t ;;; End: 

Literature:

edit:

I'm not sure that, to be honest, this will do something with this long boot time. An example of an org file of comparable size is not deleted remotely, which takes a long time to load onto my machine, but I don’t know, because it is easier to process due to better hardware or my simple stub file.

If the above does not improve the situation, we could try to narrow down before initializing org-mode and see if it doesn't matter?

The following may not be the best way to do this, but it's worth a try for performance reasons just in case it matters.

This will be instead of binding org-mode and using the variable my-org-journal for the file name, as in the first example above.

 (defadvice insert-file-contents (after my-insert-file-contents) (when (equal (expand-file-name (buffer-file-name)) (expand-file-name my-org-journal)) (require 'org) (my-org-narrow-to-month-of-entries))) (ad-activate 'insert-file-contents) 
+3
source

Create an agenda view with C-[ , then view the daily / weekly agenda with Cu 90 Cc aa . You can customize this and associate it with something, see http://www.gnu.org/software/emacs/manual/html_node/org/Custom-agenda-views.html#Custom-agenda-views .

[EDIT] This doesn’t actually answer the question of collapsing old records, but allows you to view only the relevant records.

+2
source

I don’t have a fully automated way to do what you ask. I'm sure someone with some elisp / org-mode chops could automate it.

Here are some org-mode functions that may help:

  • You can tag the headers with the Archive tag (via Cc Cx a ) and prevent them from expanding with cyclic visibility. See the org-mode archiving reference guide . I think that you achieve what you want to see.
  • As @Juancho commented, you can look for timestamps matching the expression. This creates a list of matches in which you can easily write keyboard macros to mark them as Archive. Here's a good document Advanced Search in org mode .

One annoyance that I found when trying this on my system is that the search result turned out to be a flat list of all levels of headers. As I organize the entries, it would be better to limit the search to top-level headings (this is what I use for daily entries in my journal). I'm sure you can get around this by setting some kind of property, or perhaps org-mode can filter the search at a certain level.

+2
source

You have three options:

  • set the VISIBILITY property to folded for all older records. You can use Cc a <a to limit the agenda to the current file, followed by marking the entries and setting the above en property en masse.
  • Move older journal entries to Archive Brother with Cc Cx A.
  • Archive old records into an archive file using Cc Cx Cs .
+1
source

Source: https://habr.com/ru/post/891156/


All Articles