Function: erc-button-add-button

erc-button-add-button is a byte-compiled function defined in erc-button.el.gz.

Signature

(erc-button-add-button FROM TO FUN NICK-P &optional DATA REGEXP)

Documentation

Create a button between FROM and TO with callback FUN and data DATA.

NICK-P specifies if this is a nickname button. REGEXP is the regular expression which matched for this button.

Source Code

;; Defined in /usr/src/emacs/lisp/erc/erc-button.el.gz
(defun erc-button-add-button (from to fun nick-p &optional data regexp)
  "Create a button between FROM and TO with callback FUN and data DATA.
NICK-P specifies if this is a nickname button.
REGEXP is the regular expression which matched for this button."
  ;; Really nasty hack to <URL: > ise urls, and line-wrap them if
  ;; they're going to be wider than `erc-fill-column'.
  ;; This could be a lot cleaner, but it works for me -- lawrence.
  (let (fill-column)
    (when (and erc-button-wrap-long-urls
               (string= regexp erc-button-url-regexp)
               (> (- to from)
                  (setq fill-column (- (if (numberp erc-button-wrap-long-urls)
                                           erc-button-wrap-long-urls
                                         erc-fill-column)
                                       (length erc-fill-prefix)))))
      (setq to (prog1 (point-marker) (insert ">"))
            from (prog2 (goto-char from) (point-marker) (insert "<URL: ")))
      (let ((pos (copy-marker from)))
        (while (> (- to pos) fill-column)
          (goto-char (+ pos fill-column))
          (insert "\n" erc-fill-prefix) ; This ought to figure out
                                        ; what type of filling we're
                                        ; doing, and indent accordingly.
          (move-marker pos (point))))))
  (if nick-p
      (when erc-button-nickname-face
        (erc-button-add-face from to erc-button-nickname-face))
    (when erc-button-face
      (erc-button-add-face from to erc-button-face)))
  (add-text-properties
   from to
   (nconc (and erc-button-mouse-face
               (list 'mouse-face erc-button-mouse-face))
          (list 'erc-callback fun)
          (list 'keymap erc-button-keymap)
          (list 'rear-nonsticky t)
          (and data (list 'erc-data data)))))