Function: ibut:insert-text

ibut:insert-text is a byte-compiled function defined in hbut.el.

Signature

(ibut:insert-text IBUT)

Documentation

Space, delimit and insert the text part of IBUT.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hbut.el
(defun    ibut:insert-text (ibut)
  "Space, delimit and insert the text part of IBUT."
  (when (hattr:get ibut 'name)
    (cond ((looking-at ibut:label-separator-regexp)
	   (goto-char (match-end 0)))
	  ((not (or (string-empty-p (or (hattr:get ibut 'name) ""))))
	   (insert ibut:label-separator))))
  (let* ((orig-actype (or (hattr:get ibut 'actype)
			  (hattr:get ibut 'categ)))
	 (actype (or (actype:elisp-symbol orig-actype)
		     (and (symbolp orig-actype) (fboundp orig-actype)
			  orig-actype)))
	 (args   (hattr:get ibut 'args))
	 (arg1   (nth 0 args))
	 (arg2   (nth 1 args))
	 (arg3   (nth 2 args)))
    (pcase actype
      ('actypes::kbd-key
       (cond ((and (stringp arg1) (string-match "\\s-*{.+}\\s-*" arg1))
	      (insert arg1))
	     ((stringp arg1)
	      (insert "{" arg1 "}"))
	     (t (insert "{}"))))
      ((or 'actypes::link-to-directory 'actypes::link-to-Info-node 'actypes::link-to-Info-index-item)
       (insert "\"" arg1 "\""))
      ('actypes::annot-bib (insert "[" arg1 "]"))
      ('actypes::exec-shell-cmd (insert "\"!" arg1 "\""))
      ('actypes::exec-window-cmd (insert "\"&" arg1 "\""))
      ('actypes::link-to-gbut (insert "<glink:" arg1 ">"))
      ('actypes::link-to-ebut (progn (insert "<elink:" arg1)
				     (when arg2 (insert ": " arg2))
				     (insert ">")))
      ('actypes::link-to-ibut (progn (insert "<ilink:" arg1)
				     (when arg2 (insert ": " arg2))
				     (insert ">")))
      ('actypes::link-to-kcell
       (if arg2
	   (progn (insert "<")
		  (when arg1 (insert arg1))
		  (insert ", " arg2 ">"))
	 (insert "<@ ")
	 (when arg1 (insert arg1))
	 (insert ">")))
      ((or 'actypes::link-to-kotl 'klink:act)
       (when (stringp arg1)
	 (if (string-prefix-p "<" arg1)
	     (insert arg1)
	   (insert "<" arg1 ">"))))
      ;; Insert an Org-style link here so can include the Org title linked
      ;; to for clarity.
      ('actypes::link-to-org-id
       (insert (if arg2
                   (format "[[id:%s][%s]]" arg1 arg2)
                 (format "[[id:%s]]" arg1))))
      ('actypes::link-to-rfc (insert (format "rfc%d" arg1)))
      ('actypes::link-to-wikiword (insert (if (and (stringp arg1)
                                                   (string-match-p "\\s-" arg1))
                                              ;; Double-quote when has a space
                                              (format "\"%s\"" arg1)
                                            arg1)))
      ('man (insert arg1))
      ('actypes::man-show (insert arg1))
      ('actypes::link-to-file-line (insert (format "\"%s:L%d\""
						   (hpath:shorten arg1) arg2)))
      ('actypes::link-to-file-line-and-column
       (insert
	(if (eq arg3 0)
	    (format "\"%s:L%d\"" (hpath:shorten arg1) arg2)
	  (format "\"%s:L%d:C%d\"" (hpath:shorten arg1) arg2 arg3))))
      ('actypes::link-to-file
       ;; arg2 when given is a buffer position
       (insert "\""
	       (if arg2
		   ;; includes buffer pos that we translate to line:col
		   (hpath:file-position-to-line-and-column arg1 arg2)
		 ;; filename only
		 (hpath:shorten arg1))
	       "\""))
      ('actypes::link-to-string-match
       (insert (format "\"%s#%s%s\"" (hpath:shorten arg3) arg1
		       (if (<= arg2 1) "" (concat ":I" (number-to-string arg2))))))
      ('actypes::link-to-texinfo-node
       (insert (format "\"%s#%s\"" (hpath:shorten arg1) arg2)))
      ('nil (error "(ibut:insert-text): actype must be a Hyperbole actype or Lisp function symbol, not '%s'" orig-actype))
      ;; Generic action button type
      (_ (insert (format "<%s%s%s>" (or (actype:def-symbol actype) actype)
			 (if args " " "")
			 (if args (hypb:format-args args) "")))))
    (unless (looking-at "\\s-\\|\\'")
      (insert " "))))