Function: hbdata:ebut-build

hbdata:ebut-build is a byte-compiled function defined in hbdata.el.

Signature

(hbdata:ebut-build &optional MOD-LBL-KEY BUT-SYM NEW-LBL-KEY)

Documentation

Construct button data from optional MOD-LBL-KEY and BUT-SYM.

Modify BUT-SYM attributes. MOD-LBL-KEY nil means create a new entry, otherwise modify existing one. Nil BUT-SYM means use hbut:current. If successful, return a cons of
 (button-data . button-instance-str), else nil.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hbdata.el
(defun hbdata:ebut-build (&optional mod-lbl-key but-sym new-lbl-key)
  "Construct button data from optional MOD-LBL-KEY and BUT-SYM.
Modify BUT-SYM attributes.  MOD-LBL-KEY nil means create a new
entry, otherwise modify existing one.  Nil BUT-SYM means use
`hbut:current'.  If successful, return a cons of
 (button-data . button-instance-str), else nil."
  (let* ((b (hattr:copy (or but-sym 'hbut:current) 'but))
	 (l (hattr:get b 'loc))
	 (key (or mod-lbl-key (hattr:get b 'lbl-key)))
	 (new-key (or new-lbl-key (if mod-lbl-key (hattr:get b 'lbl-key) key)))
	 (lbl-instance) (creator) (create-time) (modifier) (mod-time)
	 (entry) loc dir)
    (when l
      (setq loc (if (bufferp l) l (file-name-nondirectory l))
	    dir (if (bufferp l) nil (file-name-directory l)))
      (when (setq entry (hbdata:to-entry key loc dir (not mod-lbl-key)))
	(if mod-lbl-key
	    (progn
	      (setq creator     (hbdata:creator entry)
		    create-time (hbdata:create-time entry)
		    modifier    (let* ((user (hypb:user-name))
				       (addr hyperb:user-email))
				  (if (equal creator addr)
				      user addr))
		    mod-time    (htz:date-sortable-gmt)
		    entry       (cons new-key (cdr entry)))
	      (hbdata:delete-entry-at-point)
	      (when (setq lbl-instance (hbdata:ebut-instance-last new-key loc dir))
		(setq lbl-instance (concat hbut:instance-sep
					   (int-to-string (1+ lbl-instance))))
		;; This expression is needed to ensure that the highest
		;; numbered instance of a label appears before
		;; other instances, so 'hbdata:ebut-instance-last' will work.
		(when (hbdata:to-entry-buf loc dir)
		  (forward-line 1))))
	  (let ((inst-num (hbdata:ebut-instance-last new-key loc dir)))
	    (setq lbl-instance (when inst-num
				 (hbdata:instance-next
				  (concat new-key hbut:instance-sep
					  (int-to-string inst-num))))))))
      (when (or entry (not mod-lbl-key))
	(hattr:set b 'lbl-key (concat new-key lbl-instance))
	(hattr:set b 'loc loc)
	(hattr:set b 'dir dir)
	(let* ((actype)
	       (hbdata (list (hattr:get b 'lbl-key)
			     (hattr:get b 'action)
			     (hattr:get b 'referent)
			     ;; Save actype without class prefix.
			     (and (setq actype (hattr:get b 'actype))
				  (symbolp actype)
				  (setq actype (symbol-name actype))
				  (intern
				   (substring actype (if (string-match "::" actype)
							 (match-end 0) 0))))
			     (let ((mail-dir (and (fboundp 'hmail:composing-dir)
						  (hmail:composing-dir l)))
				   (args (hattr:get b 'args)))
			       ;; Replace matches for variable values with their variable names in any pathname args.
			       (hattr:set b 'args
					  (mapcar #'hpath:substitute-var
						  (if mail-dir
						      ;; Make pathname args absolute for outgoing mail and news messages.
						      (hpath:absolute-arguments actype args mail-dir)
						    args))))
			     (hattr:set b 'creator (or creator hyperb:user-email))
			     (hattr:set b 'create-time (or create-time (htz:date-sortable-gmt)))
			     (hattr:set b 'modifier modifier)
			     (hattr:set b 'mod-time mod-time))))
	  ;; Ensure modified attributes are saved to `but-sym' or hbut:current.
	  (hattr:copy b (or but-sym 'hbut:current))
	  (cons hbdata lbl-instance))))))