138 lines
4.9 KiB
EmacsLisp
138 lines
4.9 KiB
EmacsLisp
|
;;; ERC is terrible but lovely and here's some terrible fixes to terrible bugs, enjoy.
|
|||
|
|
|||
|
(defface erc-italics-face
|
|||
|
'((t :slant italic))
|
|||
|
"ERC face for italics")
|
|||
|
|
|||
|
(defface erc-record-separator-face
|
|||
|
'((t))
|
|||
|
"ERC face for record separator")
|
|||
|
|
|||
|
(defface erc-device-control-face
|
|||
|
'((t))
|
|||
|
"ERC face for record device control")
|
|||
|
|
|||
|
(defun erc-controls-highlight ()
|
|||
|
"Highlight IRC control chars in the buffer.
|
|||
|
This is useful for `erc-insert-modify-hook' and `erc-send-modify-hook'.
|
|||
|
Also see `erc-interpret-controls-p' and `erc-interpret-mirc-color'."
|
|||
|
(goto-char (point-min))
|
|||
|
(cond ((eq erc-interpret-controls-p 'remove)
|
|||
|
(while (re-search-forward erc-controls-remove-regexp nil t)
|
|||
|
(replace-match "")))
|
|||
|
(erc-interpret-controls-p
|
|||
|
(let ((boldp nil)
|
|||
|
(inversep nil)
|
|||
|
(underlinep nil)
|
|||
|
;; italics
|
|||
|
(italicsp nil)
|
|||
|
;; record separator
|
|||
|
(rsp nil)
|
|||
|
;; device control one
|
|||
|
(dc1 nil)
|
|||
|
(fg nil)
|
|||
|
(bg nil))
|
|||
|
(while (re-search-forward erc-controls-highlight-regexp nil t)
|
|||
|
(let ((control (match-string 1))
|
|||
|
(fg-color (match-string 2))
|
|||
|
(bg-color (match-string 4))
|
|||
|
(start (match-beginning 0))
|
|||
|
(end (+ (match-beginning 0) (length (match-string 5)))))
|
|||
|
(replace-match "" nil nil nil 1)
|
|||
|
(cond ((and erc-interpret-mirc-color (or fg-color bg-color))
|
|||
|
(setq fg fg-color)
|
|||
|
(setq bg bg-color))
|
|||
|
((string= control "\C-b")
|
|||
|
(setq boldp (not boldp)))
|
|||
|
((string= control "\C-v")
|
|||
|
(setq inversep (not inversep)))
|
|||
|
((string= control "\C-_")
|
|||
|
(setq underlinep (not underlinep)))
|
|||
|
((string= control "\C-c")
|
|||
|
(setq fg nil
|
|||
|
bg nil))
|
|||
|
((string= control "\C-g")
|
|||
|
(when erc-beep-p
|
|||
|
(ding)))
|
|||
|
;; italics
|
|||
|
((string= control "\x1D")
|
|||
|
(setq italicsp (not italicsp)))
|
|||
|
;; record separator
|
|||
|
((string= control "\x1e")
|
|||
|
(setq rsp (not rsp)))
|
|||
|
;; device control one
|
|||
|
((string= control "\x11")
|
|||
|
(setq dc1 (not dc1)))
|
|||
|
((string= control "\C-o")
|
|||
|
(setq boldp nil
|
|||
|
inversep nil
|
|||
|
underlinep nil
|
|||
|
fg nil
|
|||
|
bg nil))
|
|||
|
(t nil))
|
|||
|
(erc-controls-propertize start end
|
|||
|
boldp inversep underlinep italicsp rsp dc1 fg bg)))))
|
|||
|
(t nil)))
|
|||
|
|
|||
|
(defun erc-controls-propertize (from to boldp inversep underlinep italicsp rsp dc1 fg bg
|
|||
|
&optional str)
|
|||
|
"Prepend properties from IRC control characters between FROM and TO.
|
|||
|
If optional argument STR is provided, apply to STR, otherwise prepend properties
|
|||
|
to a region in the current buffer."
|
|||
|
(font-lock-prepend-text-property
|
|||
|
from
|
|||
|
to
|
|||
|
'font-lock-face
|
|||
|
(append (if boldp
|
|||
|
'(erc-bold-face)
|
|||
|
nil)
|
|||
|
(if inversep
|
|||
|
'(erc-inverse-face)
|
|||
|
nil)
|
|||
|
(if underlinep
|
|||
|
'(erc-underline-face)
|
|||
|
nil)
|
|||
|
;; italics
|
|||
|
(if italicsp
|
|||
|
'(erc-italics-face)
|
|||
|
nil)
|
|||
|
;; record separator
|
|||
|
(if rsp
|
|||
|
'(erc-record-separator-face)
|
|||
|
nil)
|
|||
|
;; device control one
|
|||
|
(if dc1
|
|||
|
'(erc-device-control-face)
|
|||
|
nil)
|
|||
|
(if fg
|
|||
|
(list (erc-get-fg-color-face fg))
|
|||
|
nil)
|
|||
|
(if bg
|
|||
|
(list (erc-get-bg-color-face bg))
|
|||
|
nil))
|
|||
|
str)
|
|||
|
str)
|
|||
|
|
|||
|
(setq erc-controls-highlight-regexp
|
|||
|
"\\(\\|\\|\\|\x1e\\|\\|\\|\\|\\|\\([0-9][0-9]?\\)?\\(,\\([0-9][0-9]?\\)\\)?\\)\\([^\x1e]*\\)")
|
|||
|
|
|||
|
;;; Added `t' to `format-time-string' for universal time.
|
|||
|
|
|||
|
(defun erc-format-timestamp (time format)
|
|||
|
"Return TIME formatted as string according to FORMAT.
|
|||
|
Return the empty string if FORMAT is nil."
|
|||
|
(if format
|
|||
|
(let ((ts (format-time-string format time t)))
|
|||
|
(erc-put-text-property 0 (length ts)
|
|||
|
'font-lock-face 'erc-timestamp-face ts)
|
|||
|
(erc-put-text-property 0 (length ts) 'invisible 'timestamp ts)
|
|||
|
(erc-put-text-property 0 (length ts)
|
|||
|
'isearch-open-invisible 'timestamp ts)
|
|||
|
;; N.B. Later use categories instead of this harmless, but
|
|||
|
;; inelegant, hack. -- BPT
|
|||
|
(and erc-timestamp-intangible
|
|||
|
(not erc-hide-timestamps) ; bug#11706
|
|||
|
(erc-put-text-property 0 (length ts) 'cursor-intangible t ts))
|
|||
|
ts)
|
|||
|
""))
|