diff options
Diffstat (limited to 'lisp/seam.el')
-rw-r--r-- | lisp/seam.el | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/lisp/seam.el b/lisp/seam.el index 589e947..4cc21e7 100644 --- a/lisp/seam.el +++ b/lisp/seam.el @@ -33,6 +33,7 @@ ;;; Code: (require 'seam-export) +(require 'org) (require 'cl-lib) (require 'grep) @@ -71,7 +72,10 @@ naming. Must be a function taking two arguments: TITLE and TYPE." (mapcar #'car seam-export-alist)) (defun seam-slugify (title) - (downcase (string-join (string-split title "\\W+" t) "-"))) + (setq title (string-replace "'" "" title)) + (setq title (string-split title "\\W+" t)) + (setq title (string-join title "-")) + (downcase title)) (defun seam-lookup-slug (slug) (cl-dolist (type seam-note-types) @@ -156,8 +160,7 @@ naming. Must be a function taking two arguments: TITLE and TYPE." (save-restriction (widen) (goto-char 1) - (ignore-errors - (re-search-forward (org-headline-re 1)) + (when (re-search-forward "^\\* " nil t) (let ((start (point))) (end-of-line) (let ((title (string-trim (buffer-substring-no-properties start (point))))) @@ -175,8 +178,7 @@ naming. Must be a function taking two arguments: TITLE and TYPE." (save-restriction (widen) (goto-char 1) - (ignore-errors - (re-search-forward (org-headline-re 1)) + (when (re-search-forward "^\\* " nil t) (org-element-property :SEAM_SLUG (org-element-at-point)))))) (seam-slugify (seam-get-title-from-buffer buffer)))) @@ -196,6 +198,8 @@ naming. Must be a function taking two arguments: TITLE and TYPE." (file (file-name-concat seam-note-directory type (concat slug ".org")))) + (when (string= "" slug) + (error "Cannot create a note with an empty slug")) (seam--check-conflict slug) (let ((buffer (funcall (if select #'find-file #'find-file-noselect) file))) (with-current-buffer buffer @@ -214,7 +218,7 @@ naming. Must be a function taking two arguments: TITLE and TYPE." (and self (list self))))) (let ((files (cl-loop for (title . file) in notes collect (cons (seam-format-title title (seam-get-note-type file)) file)))) - (let ((completion (string-trim (funcall seam-completing-read-function prompt files)))) + (let ((completion (string-trim (funcall seam-completing-read-function prompt (mapcar #'car files))))) (or (assoc completion files) (cons completion nil))))))) @@ -503,10 +507,11 @@ Otherwise, it's nil." update-count))) (cl-defun seam-set-buffer-name (&optional (buffer (current-buffer))) - (with-current-buffer buffer - (rename-buffer - (seam-format-title (seam-get-title-from-buffer) - (seam-get-note-type (buffer-file-name buffer)))))) + (when-let ((title (seam-get-title-from-buffer))) + (with-current-buffer buffer + (rename-buffer + (seam-format-title title + (seam-get-note-type (buffer-file-name buffer))))))) (defun seam-setup-buffer () "Setup hooks when loading a Seam file." |