ahyatt / ekg

The emacs knowledge graph, app for notes and structured data.
GNU General Public License v3.0
230 stars 19 forks source link

Feature request: use tag as buffer name #190

Open QiangF opened 1 week ago

QiangF commented 1 week ago

Because note id has no meaning to the user. I would suggest like this:

   (defun ekg-edit (note)
     "Edit an existing NOTE."
     (let ((buf (get-buffer-create (format "*EKG Edit: %s*"
                                           (string-join (seq-take
                                                         (remove-if #'ekg-date-tag-p (ekg-note-tags note))
                                                         3) " ")))))
       (set-buffer buf)
       (when (= 0 (buffer-size))
         (when (ekg-note-mode note)
           (funcall (ekg-note-mode note)))
         (ekg-edit-mode 1)
         (ekg--set-local-variables)
         (setq-local ekg-note (copy-ekg-note note) ; shallow copy
                     ekg-note-orig-note (copy-tree note) ; deep copy to avoid later change
                     ekg-note-orig-id (ekg-note-id note))
         ;; When re-editing a note that's a draft, we need to remove the draft tag
         ;; so that when we save it, it's not a draft anymore.
         (setf (ekg-note-tags ekg-note)
               (seq-difference (ekg-note-tags ekg-note) (list ekg-draft-tag)))
         (ekg-edit-display-metadata)
         (setq-local ekg-note-orig-fields (seq-uniq
                                           (mapcar #'car (ekg--metadata-fields note))
                                           #'string=))
         (insert (ekg-insert-inlines-representation
                  (ekg-note-text note) (ekg-note-inlines note)))
         (goto-char (+ 1 (overlay-end (ekg--metadata-overlay))))
         (mapc #'ekg-maybe-function-tag (ekg-note-tags ekg-note))
         (if (and (eq (ekg-note-mode note) 'org-mode)
                  ekg-notes-display-images)
             (org-redisplay-inline-images)))
       (set-buffer-modified-p nil)
       (pop-to-buffer buf)))
ahyatt commented 5 days ago

This is reasonable, at least adding the tags seems like a good idea. I had the ID in there to make sure you didn't have two buffers with the same title, but I suppose there's existing packages like uniquify that can take care of that. I have some other ideas beyond what you are saying, let me see what works.

Thanks for the suggestion!