Function: hbut:map-type

hbut:map-type is a byte-compiled function defined in hbut.el.

Signature

(hbut:map-type BUT-FUNC START-DELIM END-DELIM &optional REGEXP-MATCH INCLUDE-DELIMS)

Documentation

Apply BUT-FUNC to a set of hbuttons in the visible part of the current buffer.

The set of buttons are those whose labels are delimited by START-DELIM and END-DELIM and that match any optional REGEXP-MATCH (may be a partial match but must include delimiters).

START-DELIM defaults to ebut:label-start; END-DELIM defaults to ebut:label-end. If END-DELIM is a symbol, e.g. t, then treat START-DELIM as a regular expression which matches an entire button string including instance numbers and delimiters (REGEXP-MATCH is ignored in such cases).

Any regexp given must have grouping 1 match the label.

BUT-FUNC must take precisely three arguments: the button label, the start position of the delimited button label and its end position (positions include delimiters when INCLUDE-DELIMS is non-nil).

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hbut.el
(defun    hbut:map-type (but-func start-delim end-delim
			 &optional regexp-match include-delims)
  "Apply BUT-FUNC to a set of hbuttons in the visible part of the current buffer.
The set of buttons are those whose labels are delimited by START-DELIM
and END-DELIM and that match any optional REGEXP-MATCH (may be a partial
match but must include delimiters).

START-DELIM defaults to ebut:label-start; END-DELIM defaults to
ebut:label-end.  If END-DELIM is a symbol, e.g. t, then treat START-DELIM
as a regular expression which matches an entire button string including
instance numbers and delimiters (REGEXP-MATCH is ignored in such cases).

Any regexp given must have grouping 1 match the label.

BUT-FUNC must take precisely three arguments: the button label, the start
position of the delimited button label and its end position (positions
include delimiters when INCLUDE-DELIMS is non-nil)."
  (unless (stringp start-delim)
    (error "(hbut:map-type): `start-delim' must be a string, not '%s'"
	   start-delim))
  (unless end-delim
    (error "(hbut:map-type): `end-delim' must be non-nil"))

  (let* ((match-to-start-delim (when end-delim (symbolp end-delim)))
	 (end-char (unless match-to-start-delim
		     (substring end-delim -1)))
	 (result)
	 (ignore)
	 (regexp-to-match
	  (cond (match-to-start-delim
		 start-delim)
		((stringp regexp-match)
		 regexp-match)
		(t (concat (regexp-quote start-delim)
			   "\\([^" end-char "\"][^" end-char "]*\\)"
			   (regexp-quote end-delim)))))
	 start end delim-start lbl)
    (save-excursion
      (goto-char (point-min))
      (setq include-delims (if include-delims 0 1))
      (while (re-search-forward regexp-to-match nil t)
	(setq start (match-beginning include-delims)
	      end (match-end include-delims)
	      lbl (match-string-no-properties 1)
	      delim-start (match-beginning 0)
	      ;; If within a programming language buffer, ignore matches
	      ;; outside comments.
	      ignore (hbut:outside-comment-p))
	(save-excursion
	  (goto-char delim-start)
	  ;; Ignore matches with quoted delimiters.
	  (unless ignore
	    (setq ignore (memq (preceding-char) '(?\\ ?\{)))))
	(if ignore
	    (setq ignore nil)
	  (setq result (cons (funcall but-func lbl start end) result)))))
    (nreverse result)))