Function: hyrolo-edit

hyrolo-edit is an autoloaded, interactive and byte-compiled function defined in hyrolo.el.

Signature

(hyrolo-edit &optional NAME FILE-OR-BUF)

Documentation

Edit a hyrolo entry matching NAME from FILE-OR-BUF.

With prefix argument, prompt for optional FILE-OR-BUF from hyrolo-file-list, within which to locate entry. With no NAME arg, simply display FILE-OR-BUF or the first entry in hyrolo-file-list in an editable mode. NAME may be of the form: parent/child to edit child below a parent entry which begins with the parent string.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hyrolo.el
;;;###autoload
(defun hyrolo-edit (&optional name file-or-buf)
  "Edit a hyrolo entry matching NAME from FILE-OR-BUF.
With prefix argument, prompt for optional FILE-OR-BUF from `hyrolo-file-list',
within which to locate entry.  With no NAME arg, simply display
FILE-OR-BUF or the first entry in `hyrolo-file-list' in an editable
mode.  NAME may be of the form: parent/child to edit child below
a parent entry which begins with the parent string."
  (interactive (list
		(hsys-consult-grep-headlines-read-regexp
		 #'hyrolo-consult-grep "Edit rolo entry named")
		current-prefix-arg))
  (when (string-empty-p name)
    (setq name nil))
  (when (and name (not (stringp name)))
    (error "(hyrolo-edit): Invalid name: `%s'" name))

  ;; With consult-grep, 'name' is the entire line matched prefixed
  ;; by filename and line number, so remove these prefixes.
  (when (and name
	     (hsys-consult-active-p)
	     (string-match "\\([^ \t\n\r\"'`]*[^ \t\n\r:\"'`0-9]\\): ?\\([1-9][0-9]*\\)[ :]"
			   name))
    (setq file-or-buf (expand-file-name (match-string 1 name))
	  name (substring name (match-end 0)))
    (put-text-property 0 1 'hyrolo-line-entry 0 name))

  (let* ((found-point)
	 (all-files-or-bufs (hyrolo-get-file-list))
	 (file-or-buf-list (if file-or-buf (list file-or-buf) all-files-or-bufs)))
    (when (and (called-interactively-p 'interactive) current-prefix-arg)
      (setq file-or-buf
	    (if (cadr all-files-or-bufs) ;; length > 1
		(car all-files-or-bufs)
	      (completing-read "File of entry to edit: "
			       (mapcar #'list all-files-or-bufs)))))
    (unless file-or-buf
      (setq file-or-buf (car file-or-buf-list)))

    (if (or (null name)
	    (setq found-point (hyrolo-to name (list file-or-buf))))
	(cond ((stringp file-or-buf)
	       (unless (file-writable-p file-or-buf)
		 (error "(hyrolo-edit): File not writable: `%s'" file-or-buf))
	       (hpath:find file-or-buf)
	       (setq buffer-read-only nil)
	       (set-auto-mode t))
	      ((bufferp file-or-buf)
	       (unless (buffer-live-p file-or-buf)
		 (error "(hyrolo-edit): Buffer is not live: `%s'" file-or-buf))
	       (when (hyrolo-to-buffer file-or-buf)
		 (barf-if-buffer-read-only)))
	      (t (error "(hyrolo-edit): Second argument must be a file or buffer, not: `%s'" file-or-buf)))
      (message "(hyrolo-edit): `%s' not found." name)
      (beep)
      (hyrolo-to-buffer (or (get-buffer file-or-buf)
			    (hyrolo-find-file-noselect file-or-buf)))
      (setq buffer-read-only nil))
    (when name
      (hyrolo-widen)
      ;; hyrolo-to-buffer may have moved point from its desired location, so
      ;; restore it.
      (when found-point
	(goto-char found-point)
	(set-auto-mode t)
	(hmouse-pulse-line))
      (when (derived-mode-p 'kotl-mode)
	(kotl-mode:to-valid-position))
      (unless (get-text-property 0 'hyrolo-line-entry name)
	;; Run hooks like adding a date only when handling a
	;; delimited (rather than single-line) entry.
	(run-hooks 'hyrolo-edit-hook)))))