~protesilaos/denote

1

Is there a way to sort note files by title or tags

Details
Message ID
<1C75FF01-EC76-49DF-9AEB-ED718A2795FF@gmail.com>
DKIM signature
missing
Download raw message
Hello everyone, this question may be more suitable to explore how to configure dired. But I did have problems integrating denote and dired. So please give me a little time. 

When I retrieve my denote notes in emacs, by default I can only sort by file name (i.e. denote id, 20220901Txxxx) or by time. But one of my favorite methods is grown new notes under the current note.

Since I couldn't upload pictures, I tried to draw them:

       Step1 
       
    +---------+
    |    0    |
    +---------+
          
    +---------+
    |    1    |
    +---------+
          
    +---------+
    |    2    |
    +---------+
          
    +---------+
    |    3    |
    +---------+

       Step2, injected note 1a,1b between 1 and 2
       
    +---------+
    |    0    |
    +---------+
                         
    +---------+         
    |    1    |         
    +---------+
                    +---------+
                    |    1a   |
                    +---------+
                    +---------+
                    |    1b   |
                    +---------+

    +---------+
    |    2    |
    +---------+

    +---------+
    |    3    |
    +————+


       Step3, injected note 1a1,1a2 between 1a and 1b
       
    +---------+
    |    0    |
    +---------+

    +---------+
    |    1    |
    +----+----+
         |          +---------+
         |          |    1a   |
         |          +----+----+
         |               |       +--------+
         |               |       |   1a1  |
         +               |       +--------+
         |               |       +--------+
         |               |       |   1a2  |
         |               |       +--------+
         |          +----+-----+
         |          |    1b    |
         +          +----------+
    +---------+
    |    2    |
    +---------+
          
    +---------+
    |    3    |

Eg, we hava a list of files:
20220901T000000–1-computer-science_cs.org
20220903T000000–1a-elisp_cs.org
20220902T000000–1b-cpp_cs.org
20220902T010000–1b1_class_cs.org
20220905T010000–1c_java_cs.org

It can be found that no file name or time order is used. And we get a tree-like order which is much useful when the number of note has increased a lot. In this way, I can quickly browse all my notes files in a flat folder while maintaining a reasonable tree structure. 

This approach relies on sorting titles, and if I use the linux sort command, such as "sort -t - -k1” , it can display the results of sorting by titles that are the first field after “—“ in the denote name scheme. But I don’t know how to use this method to browse my note in dired, and the I can quickly select  target notes.
Details
Message ID
<87y1u2wyum.fsf@protesilaos.com>
In-Reply-To
<1C75FF01-EC76-49DF-9AEB-ED718A2795FF@gmail.com> (view parent)
DKIM signature
missing
Download raw message
> From: yi liu <lewisliu.gm@gmail.com>
> Date: Thu, 29 Sep 2022 12:20:57 +0800
>
> Hello everyone,

Hello there!

> this question may be more suitable to explore how to configure
> dired. But I did have problems integrating denote and dired. So please
> give me a little time.
>
> When I retrieve my denote notes in emacs, by default I can only sort
> by file name (i.e. denote id, 20220901Txxxx) or by time. But one of my
> favorite methods is grown new notes under the current note.
>
> Since I couldn't upload pictures, I tried to draw them:

Your drawings were helpful.  I updated the settings of the mailing list
to accept image attachments as well.

> [... 71 lines elided]

> Eg, we hava a list of files:
> 20220901T000000–1-computer-science_cs.org
> 20220903T000000–1a-elisp_cs.org
> 20220902T000000–1b-cpp_cs.org
> 20220902T010000–1b1_class_cs.org
> 20220905T010000–1c_java_cs.org
>
> It can be found that no file name or time order is used. And we get a
> tree-like order which is much useful when the number of note has
> increased a lot. In this way, I can quickly browse all my notes files
> in a flat folder while maintaining a reasonable tree structure.
>
> This approach relies on sorting titles, and if I use the linux sort
> command, such as "sort -t - -k1” , it can display the results of
> sorting by titles that are the first field after “—“ in the denote
> name scheme. But I don’t know how to use this method to browse my note
> in dired, and the I can quickly select target notes.

I don't know how to achieve this within a Dired buffer.  With Dired, we
are basically relying on the output of 'ls'.  We can change its flags by
passing 'C-u' to 'dired-sort-toggle-or-edit', such as 'C-u s' with the
default key bindings.

Perhaps this is where 'dired-virtual-mode' comes in handy.  Use 'M-x
shell' or 'M-x eshell' to run a command like 'ls -l | sort -t - -k1'.
Place the output in its own buffer and then use 'M-x' again to invoke
'dired-virtual-mode'.

To speed up the process of capturing a command's output to a buffer, I
use the following for Eshell:

    (defcustom prot-eshell-output-buffer "*Exported Eshell output*"
      "Name of buffer with the last output of Eshell command.
    Used by `prot-eshell-export'."
      :type 'string
      :group 'prot-eshell)

    (defcustom prot-eshell-output-delimiter "* * *"
      "Delimiter for successive `prot-eshell-export' outputs.
    This is formatted internally to have newline characters before
    and after it."
      :type 'string
      :group 'prot-eshell)

    (defun prot-eshell--command-prompt-output ()
      "Capture last command prompt and its output."
      (let ((beg (save-excursion
                   (goto-char (eshell-beginning-of-input))
                   (goto-char (point-at-bol)))))
      (when (derived-mode-p 'eshell-mode)
        (buffer-substring-no-properties beg (eshell-end-of-output)))))

    ;;;###autoload
    (defun prot-eshell-export ()
      "Produce a buffer with output of the last Eshell command.
    If `prot-eshell-output-buffer' does not exist, create it.  Else
    append to it, while separating multiple outputs with
    `prot-eshell-output-delimiter'."
      (interactive)
      (let ((eshell-output (prot-eshell--command-prompt-output)))
        (with-current-buffer (get-buffer-create prot-eshell-output-buffer)
          (let ((inhibit-read-only t))
            (goto-char (point-max))
            (unless (eq (point-min) (point-max))
              (insert (format "\n%s\n\n" prot-eshell-output-delimiter)))
            (goto-char (point-at-bol))
            (insert eshell-output)
            (switch-to-buffer-other-window (current-buffer))))))

Bind 'prot-eshell-export' to a key in the 'eshell-mode-map' and give it
a try (I use 'C-c C-e').

The "virtual" Dired buffer does not have all the features of Dired.  But
it does open files.  Maybe that will do?

If there is a better method, I am curious to learn about it.

All the best,
Protesilaos (or simply "Prot")

-- 
Protesilaos Stavrou
https://protesilaos.com
Reply to thread Export thread (mbox)