Function: hui:ibut-edit

hui:ibut-edit is an interactive and byte-compiled function defined in hui.el.

Signature

(hui:ibut-edit LBL-KEY)

Documentation

Edit a named implicit Hyperbole button given by LBL-KEY.

Signal an error when no such button is found in the current buffer.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hui.el
(defun hui:ibut-edit (lbl-key)
  "Edit a named implicit Hyperbole button given by LBL-KEY.
Signal an error when no such button is found in the current buffer."
  (interactive (list (save-excursion
		       (hui:buf-writable-err (current-buffer) "ibut-edit")
		       (ibut:label-to-key
			(hargs:read-match "Button to edit: "
					  (ibut:alist) nil t
					  (ibut:label-p t) 'ibut)))))
  (unless (stringp lbl-key)
    (if (called-interactively-p 'interactive)
	(error "(hui:ibut-edit): No named implicit button to edit")
      (error "(hui:ibut-edit): 'lbl-key' argument must be a string, not '%s'" lbl-key)))

  (hypb:assert-same-start-and-end-buffer
    (let ((lbl (ibut:key-to-label lbl-key))
          (interactive-flag (called-interactively-p 'interactive))
	  (but-buf (current-buffer))
	  new-lbl)
      (hattr:set 'hbut:current 'loc (hui:key-src but-buf))
      (hattr:set 'hbut:current 'dir (hui:key-dir but-buf))
      (save-excursion
	(unless (called-interactively-p 'interactive)
	  (hui:buf-writable-err but-buf "ibut-edit"))

	(unless (ibut:get lbl-key but-buf)
	  (pop-to-buffer but-buf)
	  (hypb:error "(ibut-edit): Invalid button, no data for '%s'" lbl))

	(setq new-lbl
	      (hargs:read
	       "Change button name to: "
	       (lambda (lbl)
		 (and (not (string-equal lbl "")) (<= (length lbl) (hbut:max-len))))
	       lbl
	       (format "(ibut-edit): Enter a string of at most %s chars."
		       (hbut:max-len))
	       'string))

	;; Implicit buttons
	(with-current-buffer but-buf
	  (save-excursion
            (ibut:to lbl-key)
	    (if (and interactive-flag (ibut:at-p))
		(progn
                  ;; lbl-start and lbl-end mark the text of the ibut, not
                  ;; its name.
                  (when (hattr:get 'hbut:current 'lbl-end)
                    (let* ((start (hattr:get 'hbut:current 'lbl-start))
                           (end (hattr:get 'hbut:current 'lbl-end))
                           (old-text (buffer-substring start end))
                           (new-text (read-string "Edit ibut text: " old-text)))
                      (save-excursion
			(goto-char start)
			(delete-region start end)
			(insert new-text))
                      (hattr:set 'hbut:current 'lbl-key (ibut:label-to-key new-lbl))))
                  ;; Have to do name change after lbl-start/lbl-end are
                  ;; used so buffer positions do not change.
                  (ibut:rename lbl new-lbl)
                  (save-buffer)
                  (hui:ibut-message t))
              (when (and interactive-flag
			 (ibut:rename lbl new-lbl))
		(save-buffer)
		(message "Button renamed to %s%s%s"
			 ibut:label-start
			 new-lbl
			 ibut:label-end)))))))))