1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-29 07:58:28 +00:00
emacs/lisp/erc/erc-fill.el

192 lines
6.7 KiB
EmacsLisp
Raw Normal View History

lisp/erc: Use lexical-binding Also remove various redundant `:group` arguments. * lisp/erc/erc-backend.el (define-erc-response-handler): Move `declare` after the docstring. * lisp/erc/erc-capab.el: Use lexical-binding. (erc-capab-identify-activate): Simplify with `member`. * lisp/erc/erc-dcc.el (erc-dcc): Move before erc-dcc-mode definition, which refers to it. (erc-dcc-chat-accept): Remove unused vars `nick` and `buffer`. * lisp/erc/erc-imenu.el: Use lexical-binding. (erc-create-imenu-index): Remove unused var `prev-pos`. * lisp/erc/erc-match.el: Use lexical-binding. (erc-match-message): Remove unused var `old-pt`. (erc-match-message): Strength-reduce `eval` to `symbol-value`. * lisp/erc/erc-page.el: Use lexical-binding. (erc-page): Move Custom group before `erg-page-mode` which refers to it. * lisp/erc/erc-replace.el: Use lexical-binding. (erc-replace-insert): Use `functionp`. * lisp/erc/erc-status-sidebar.el: Use lexical-binding. (erc-status-sidebar-open): Remove unused var `sidebar-window`. * lisp/erc/erc.el: Fix header to use the customary 3 semi-colons. (erc-fill-column): Declare variable. * lisp/erc/erc-autoaway.el: Use lexical-binding. * lisp/erc/erc-ezbounce.el: Use lexical-binding. * lisp/erc/erc-fill.el: Use lexical-binding. * lisp/erc/erc-goodies.el: Use lexical-binding. * lisp/erc/erc-ibuffer.el: Use lexical-binding. * lisp/erc/erc-identd.el: Use lexical-binding. * lisp/erc/erc-join.el: Use lexical-binding. * lisp/erc/erc-lang.el: Use lexical-binding. * lisp/erc/erc-log.el: Use lexical-binding. * lisp/erc/erc-menu.el: Use lexical-binding. * lisp/erc/erc-netsplit.el: Use lexical-binding. * lisp/erc/erc-networks.el: Use lexical-binding. * lisp/erc/erc-pcomplete.el: Use lexical-binding. * lisp/erc/erc-ring.el: Use lexical-binding. * lisp/erc/erc-speedbar.el: Use lexical-binding. * lisp/erc/erc-spelling.el: Use lexical-binding. * lisp/erc/erc-truncate.el: Use lexical-binding. * lisp/erc/erc-xdcc.el: Use lexical-binding.
2021-03-19 03:14:33 +00:00
;;; erc-fill.el --- Filling IRC messages in various ways -*- lexical-binding: t; -*-
;; Copyright (C) 2001-2004, 2006-2021 Free Software Foundation, Inc.
;; Author: Andreas Fuchs <asf@void.at>
;; Mario Lang <mlang@delysid.org>
2020-03-19 01:27:49 +00:00
;; Maintainer: Amin Bandali <bandali@gnu.org>
;; URL: https://www.emacswiki.org/emacs/ErcFilling
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This package implements filling of messages sent and received. Use
;; `erc-fill-mode' to switch it on. Customize `erc-fill-function' to
;; change the style.
;;; Code:
(require 'erc)
(require 'erc-stamp); for the timestamp stuff
(defgroup erc-fill nil
"Filling means to reformat long lines in different ways."
:group 'erc)
;;;###autoload(autoload 'erc-fill-mode "erc-fill" nil t)
(define-minor-mode erc-fill-mode
"Toggle ERC fill mode.
Fix more minor mode docstrings. * lisp/emulation/cua-base.el (cua-mode): * lisp/mail/footnote.el (footnote-mode): * lisp/mail/mailabbrev.el (mail-abbrevs-mode): * lisp/net/xesam.el (xesam-minor-mode): * lisp/progmodes/bug-reference.el (bug-reference-mode): * lisp/progmodes/cap-words.el (capitalized-words-mode): * lisp/progmodes/compile.el (compilation-minor-mode) (compilation-shell-minor-mode): * lisp/progmodes/gud.el (gud-tooltip-mode): * lisp/progmodes/hideif.el (hide-ifdef-mode): * lisp/progmodes/idlw-shell.el (idlwave-shell-electric-debug-mode): * lisp/progmodes/subword.el (subword-mode): * lisp/progmodes/vhdl-mode.el (vhdl-electric-mode, vhdl-stutter-mode): * lisp/progmodes/which-func.el (which-function-mode): * lisp/term/tvi970.el (tvi970-set-keypad-mode): * lisp/term/vt100.el (vt100-wide-mode): * lisp/textmodes/flyspell.el (flyspell-mode): * lisp/textmodes/ispell.el (ispell-minor-mode): * lisp/textmodes/nroff-mode.el (nroff-electric-mode): * lisp/textmodes/paragraphs.el (use-hard-newlines): * lisp/textmodes/refill.el (refill-mode): * lisp/textmodes/reftex.el (reftex-mode): * lisp/textmodes/rst.el (rst-minor-mode): * lisp/textmodes/sgml-mode.el (html-autoview-mode) (sgml-electric-tag-pair-mode): * lisp/textmodes/tex-mode.el (latex-electric-env-pair-mode): * lisp/vc/diff-mode.el (diff-auto-refine-mode, diff-minor-mode): * lisp/emulation/crisp.el (crisp-mode): * lisp/emacs-lisp/eldoc.el (eldoc-mode): * lisp/emacs-lisp/checkdoc.el (checkdoc-minor-mode): Doc fixes for new minor mode behavior. * lisp/erc/erc-fill.el (erc-fill-mode): * lisp/erc/erc-track.el (erc-track-minor-mode): Doc fix. * lisp/erc/erc.el (define-erc-module): Fix autogenerated docstring to reflect Emacs 24 minor mode changes. * lisp/gnus/gnus-cite.el (gnus-message-citation-mode): Doc fix (in Emacs 24, calling a minor mode from Lisp with nil arg enables it, so we have to make the working a bit ambiguous here).
2011-10-20 00:26:14 +00:00
With a prefix argument ARG, enable ERC fill mode if ARG is
positive, and disable it otherwise. If called from Lisp, enable
the mode if ARG is omitted or nil.
ERC fill mode is a global minor mode. When enabled, messages in
the channel buffers are filled."
lisp/erc: Use lexical-binding Also remove various redundant `:group` arguments. * lisp/erc/erc-backend.el (define-erc-response-handler): Move `declare` after the docstring. * lisp/erc/erc-capab.el: Use lexical-binding. (erc-capab-identify-activate): Simplify with `member`. * lisp/erc/erc-dcc.el (erc-dcc): Move before erc-dcc-mode definition, which refers to it. (erc-dcc-chat-accept): Remove unused vars `nick` and `buffer`. * lisp/erc/erc-imenu.el: Use lexical-binding. (erc-create-imenu-index): Remove unused var `prev-pos`. * lisp/erc/erc-match.el: Use lexical-binding. (erc-match-message): Remove unused var `old-pt`. (erc-match-message): Strength-reduce `eval` to `symbol-value`. * lisp/erc/erc-page.el: Use lexical-binding. (erc-page): Move Custom group before `erg-page-mode` which refers to it. * lisp/erc/erc-replace.el: Use lexical-binding. (erc-replace-insert): Use `functionp`. * lisp/erc/erc-status-sidebar.el: Use lexical-binding. (erc-status-sidebar-open): Remove unused var `sidebar-window`. * lisp/erc/erc.el: Fix header to use the customary 3 semi-colons. (erc-fill-column): Declare variable. * lisp/erc/erc-autoaway.el: Use lexical-binding. * lisp/erc/erc-ezbounce.el: Use lexical-binding. * lisp/erc/erc-fill.el: Use lexical-binding. * lisp/erc/erc-goodies.el: Use lexical-binding. * lisp/erc/erc-ibuffer.el: Use lexical-binding. * lisp/erc/erc-identd.el: Use lexical-binding. * lisp/erc/erc-join.el: Use lexical-binding. * lisp/erc/erc-lang.el: Use lexical-binding. * lisp/erc/erc-log.el: Use lexical-binding. * lisp/erc/erc-menu.el: Use lexical-binding. * lisp/erc/erc-netsplit.el: Use lexical-binding. * lisp/erc/erc-networks.el: Use lexical-binding. * lisp/erc/erc-pcomplete.el: Use lexical-binding. * lisp/erc/erc-ring.el: Use lexical-binding. * lisp/erc/erc-speedbar.el: Use lexical-binding. * lisp/erc/erc-spelling.el: Use lexical-binding. * lisp/erc/erc-truncate.el: Use lexical-binding. * lisp/erc/erc-xdcc.el: Use lexical-binding.
2021-03-19 03:14:33 +00:00
:global t
(if erc-fill-mode
(erc-fill-enable)
(erc-fill-disable)))
(defun erc-fill-enable ()
"Setup hooks for `erc-fill-mode'."
(interactive)
lisp/erc: Use lexical-binding Also remove various redundant `:group` arguments. * lisp/erc/erc-backend.el (define-erc-response-handler): Move `declare` after the docstring. * lisp/erc/erc-capab.el: Use lexical-binding. (erc-capab-identify-activate): Simplify with `member`. * lisp/erc/erc-dcc.el (erc-dcc): Move before erc-dcc-mode definition, which refers to it. (erc-dcc-chat-accept): Remove unused vars `nick` and `buffer`. * lisp/erc/erc-imenu.el: Use lexical-binding. (erc-create-imenu-index): Remove unused var `prev-pos`. * lisp/erc/erc-match.el: Use lexical-binding. (erc-match-message): Remove unused var `old-pt`. (erc-match-message): Strength-reduce `eval` to `symbol-value`. * lisp/erc/erc-page.el: Use lexical-binding. (erc-page): Move Custom group before `erg-page-mode` which refers to it. * lisp/erc/erc-replace.el: Use lexical-binding. (erc-replace-insert): Use `functionp`. * lisp/erc/erc-status-sidebar.el: Use lexical-binding. (erc-status-sidebar-open): Remove unused var `sidebar-window`. * lisp/erc/erc.el: Fix header to use the customary 3 semi-colons. (erc-fill-column): Declare variable. * lisp/erc/erc-autoaway.el: Use lexical-binding. * lisp/erc/erc-ezbounce.el: Use lexical-binding. * lisp/erc/erc-fill.el: Use lexical-binding. * lisp/erc/erc-goodies.el: Use lexical-binding. * lisp/erc/erc-ibuffer.el: Use lexical-binding. * lisp/erc/erc-identd.el: Use lexical-binding. * lisp/erc/erc-join.el: Use lexical-binding. * lisp/erc/erc-lang.el: Use lexical-binding. * lisp/erc/erc-log.el: Use lexical-binding. * lisp/erc/erc-menu.el: Use lexical-binding. * lisp/erc/erc-netsplit.el: Use lexical-binding. * lisp/erc/erc-networks.el: Use lexical-binding. * lisp/erc/erc-pcomplete.el: Use lexical-binding. * lisp/erc/erc-ring.el: Use lexical-binding. * lisp/erc/erc-speedbar.el: Use lexical-binding. * lisp/erc/erc-spelling.el: Use lexical-binding. * lisp/erc/erc-truncate.el: Use lexical-binding. * lisp/erc/erc-xdcc.el: Use lexical-binding.
2021-03-19 03:14:33 +00:00
(add-hook 'erc-insert-modify-hook #'erc-fill)
(add-hook 'erc-send-modify-hook #'erc-fill))
(defun erc-fill-disable ()
"Cleanup hooks, disable `erc-fill-mode'."
(interactive)
lisp/erc: Use lexical-binding Also remove various redundant `:group` arguments. * lisp/erc/erc-backend.el (define-erc-response-handler): Move `declare` after the docstring. * lisp/erc/erc-capab.el: Use lexical-binding. (erc-capab-identify-activate): Simplify with `member`. * lisp/erc/erc-dcc.el (erc-dcc): Move before erc-dcc-mode definition, which refers to it. (erc-dcc-chat-accept): Remove unused vars `nick` and `buffer`. * lisp/erc/erc-imenu.el: Use lexical-binding. (erc-create-imenu-index): Remove unused var `prev-pos`. * lisp/erc/erc-match.el: Use lexical-binding. (erc-match-message): Remove unused var `old-pt`. (erc-match-message): Strength-reduce `eval` to `symbol-value`. * lisp/erc/erc-page.el: Use lexical-binding. (erc-page): Move Custom group before `erg-page-mode` which refers to it. * lisp/erc/erc-replace.el: Use lexical-binding. (erc-replace-insert): Use `functionp`. * lisp/erc/erc-status-sidebar.el: Use lexical-binding. (erc-status-sidebar-open): Remove unused var `sidebar-window`. * lisp/erc/erc.el: Fix header to use the customary 3 semi-colons. (erc-fill-column): Declare variable. * lisp/erc/erc-autoaway.el: Use lexical-binding. * lisp/erc/erc-ezbounce.el: Use lexical-binding. * lisp/erc/erc-fill.el: Use lexical-binding. * lisp/erc/erc-goodies.el: Use lexical-binding. * lisp/erc/erc-ibuffer.el: Use lexical-binding. * lisp/erc/erc-identd.el: Use lexical-binding. * lisp/erc/erc-join.el: Use lexical-binding. * lisp/erc/erc-lang.el: Use lexical-binding. * lisp/erc/erc-log.el: Use lexical-binding. * lisp/erc/erc-menu.el: Use lexical-binding. * lisp/erc/erc-netsplit.el: Use lexical-binding. * lisp/erc/erc-networks.el: Use lexical-binding. * lisp/erc/erc-pcomplete.el: Use lexical-binding. * lisp/erc/erc-ring.el: Use lexical-binding. * lisp/erc/erc-speedbar.el: Use lexical-binding. * lisp/erc/erc-spelling.el: Use lexical-binding. * lisp/erc/erc-truncate.el: Use lexical-binding. * lisp/erc/erc-xdcc.el: Use lexical-binding.
2021-03-19 03:14:33 +00:00
(remove-hook 'erc-insert-modify-hook #'erc-fill)
(remove-hook 'erc-send-modify-hook #'erc-fill))
(defcustom erc-fill-prefix nil
"Values used as `fill-prefix' for `erc-fill-variable'.
nil means fill with space, a string means fill with this string."
:type '(choice (const nil) string))
(defcustom erc-fill-function 'erc-fill-variable
"Function to use for filling messages.
Variable Filling with an `erc-fill-prefix' of nil:
<shortnick> this is a very very very long message with no
meaning at all
Variable Filling with an `erc-fill-prefix' of four spaces:
<shortnick> this is a very very very long message with no
meaning at all
Static Filling with `erc-fill-static-center' of 27:
<shortnick> foo bar baz
<a-very-long-nick> foo bar baz quuuuux
<shortnick> this is a very very very long message with no
meaning at all
These two styles are implemented using `erc-fill-variable' and
`erc-fill-static'. You can, of course, define your own filling
function. Narrowing to the region in question is in effect while your
function is called."
:type '(choice (const :tag "Variable Filling" erc-fill-variable)
(const :tag "Static Filling" erc-fill-static)
function))
(defcustom erc-fill-static-center 27
"Column around which all statically filled messages will be centered.
This column denotes the point where the ` ' character between
<nickname> and the entered text will be put, thus aligning nick
names right and text left."
:type 'integer)
(defcustom erc-fill-variable-maximum-indentation 17
"Don't indent a line after a long nick more than this many characters.
Set to nil to disable."
:type 'integer)
(defcustom erc-fill-column 78
"The column at which a filled paragraph is broken."
:type 'integer)
;;;###autoload
(defun erc-fill ()
"Fill a region using the function referenced in `erc-fill-function'.
You can put this on `erc-insert-modify-hook' and/or `erc-send-modify-hook'."
(unless (erc-string-invisible-p (buffer-substring (point-min) (point-max)))
(when erc-fill-function
;; skip initial empty lines
(goto-char (point-min))
(save-match-data
(while (and (looking-at "[ \t\n]*$")
(= (forward-line 1) 0))))
(unless (eobp)
(save-restriction
(narrow-to-region (point) (point-max))
(funcall erc-fill-function))))))
(defun erc-fill-static ()
"Fills a text such that messages start at column `erc-fill-static-center'."
(save-match-data
(goto-char (point-min))
(looking-at "^\\(\\S-+\\)")
(let ((nick (match-string 1)))
(let ((fill-column (- erc-fill-column (erc-timestamp-offset)))
(fill-prefix (make-string erc-fill-static-center 32)))
(insert (make-string (max 0 (- erc-fill-static-center
(length nick) 1))
32))
(erc-fill-regarding-timestamp))
(erc-restore-text-properties))))
(defun erc-fill-variable ()
"Fill from `point-min' to `point-max'."
(let ((fill-prefix erc-fill-prefix)
(fill-column (or erc-fill-column fill-column)))
(goto-char (point-min))
(if fill-prefix
(let ((first-line-offset (make-string (erc-timestamp-offset) 32)))
(insert first-line-offset)
(fill-region (point-min) (point-max) t t)
(goto-char (point-min))
(delete-char (length first-line-offset)))
(save-match-data
(let* ((nickp (looking-at "^\\(\\S-+\\)"))
(nick (if nickp
(match-string 1)
""))
(fill-column (- erc-fill-column (erc-timestamp-offset)))
(fill-prefix (make-string (min (+ 1 (length nick))
(- fill-column 1)
(or erc-fill-variable-maximum-indentation
fill-column))
32)))
(erc-fill-regarding-timestamp))))
(erc-restore-text-properties)))
(defun erc-fill-regarding-timestamp ()
"Fills a text such that messages start at column `erc-fill-static-center'."
(fill-region (point-min) (point-max) t t)
(goto-char (point-min))
(forward-line)
(indent-rigidly (point) (point-max) (erc-timestamp-offset)))
(defun erc-timestamp-offset ()
"Get length of timestamp if inserted left."
(if (and (boundp 'erc-timestamp-format)
erc-timestamp-format
(eq erc-insert-timestamp-function 'erc-insert-timestamp-left)
(not erc-hide-timestamps))
(length (format-time-string erc-timestamp-format))
0))
(provide 'erc-fill)
;;; erc-fill.el ends here
;; Local Variables:
;; generated-autoload-file: "erc-loaddefs.el"
;; End: