sympodius / org-novelist

Org Novelist is a system for writing novel-length fiction using Emacs Org mode.
GNU General Public License v3.0
183 stars 14 forks source link

Insert character name or alias #12

Open abarocio80 opened 1 year ago

abarocio80 commented 1 year ago

I have a suggestion to insert a character's name or alias:

(defun orgn--select-character-name-or-alias ()
  "Selects the character name or alias from the character notes."
  (replace-regexp-in-string
   ".* --- " ""
   (completing-read
    "Selecciona un nombre de personaje: "
    (let ((default-directory (expand-file-name (org-novelist--story-root-folder))))
      (flatten-list
       (mapcar
    (lambda (file)
      (with-current-buffer (find-file-noselect file)
        (let* ((kw (org-collect-keywords '("title" "aliases")))
           (full (nth 1 (car kw)))
           (alias (nth 1 (cadr kw))))
          (flatten-list
           (list
        (format "%s" full)
        (when alias
          (mapcar
           (lambda (n)
             (format "%s --- %s" full (string-trim n)))
           (split-string alias ","))))))))
    (directory-files (expand-file-name "Notes" default-directory) t "character-.*\\.org$"))))
    nil t)))

(defun org-novelist-insert-character-name ()
  "Iserts a character's name or alias from the character notes."
  (interactive)
  (insert (orgn--select-character-name-or-alias)))

I didn't want to make a full PR, so I just drop it here.

I hope it is useful (I know it is for me).

sympodius commented 8 months ago

Sorry, I should have responded to this a while ago. This is a cool idea! I'll try to include this feature in a future update. Thanks for sharing!