help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: file metadata


From: James Thomas
Subject: Re: file metadata
Date: Wed, 16 Oct 2024 05:02:07 +0530
User-agent: Gnus/5.13 (Gnus v5.13)

James Thomas wrote:

> James Thomas wrote:
>
>> Christopher Howard wrote:
>>
>>> Hi, I have a bunch of files in various project that have
>>> non-descriptive names, but I don't want to change the file names, nor
>>> the file contents. It would be nice if there was some way I could
>>> display my own description of the file next to the the file listing,
>>> say in dired. Do we have any kind of extension, ideally with dired
>>> integration, that provides some of kind of file metadata system, or
>>> interacts with a third party metadata system?
>>
>> I had a system where I used:
>>
>> (let ((backup-directory-alist '(("." . "~/denote"))))
>>   (make-backup-file-name-1 (expand-file-name
>>   (file-name-with-extension filename "org"))))
>>
>> ...to automatically check for a corresponding denote file with metadata.
>
> Wth, I decided to write it again. Sharing if useful for Denote users:

Updated version that accounts for 'keywords' (_after_ the original file
extension):

--8<---------------cut here---------------start------------->8---
;; Metadata for files

(defun denote-metadata (file)
  (interactive
   (list (read-file-name "Metadata for file: ")))
  (find-file
   (let* ((backup-directory-alist `(("." . ,(denote-directory))))
          (name (make-backup-file-name-1
                 (expand-file-name file))))
     (expand-file-name
      (concat
       (denote-get-identifier) "--"
       (file-name-nondirectory name) ".org")
      (file-name-directory name))))))

(defun my/dired-mark-files-with-metadata nil
  (interactive)
  (save-excursion
    (let* ((backup-directory-alist '(("." . "/")))
           (d (file-relative-name
               (make-backup-file-name-1
                (expand-file-name default-directory))
               "/"))
           temp
           (hits 0))
      (mapcar
       (lambda (f)
         (goto-char (point-min))
         (when
             (search-forward-regexp
              (format
               "\\s %s[*@]?$"
               (string-remove-suffix
                (if (setq temp (denote-retrieve-filename-keywords f))
                  (concat "__" temp) "")
                (file-name-sans-extension
                 (string-remove-prefix
                  d
                  (string-trim-left
                   f (concat denote-id-regexp "--"))))))
              nil t)
           (setq hits (1+ hits))
           (dired-mark 1)))
       (directory-files
        (denote-directory) nil
        (concat "\\`" denote-id-regexp "--" d)))
      (message "%d files with metadata marked" hits))))
--8<---------------cut here---------------end--------------->8---

--



reply via email to

[Prev in Thread] Current Thread [Next in Thread]