|
From: Brian P. <bp...@re...> - 2004-10-17 09:00:19
|
I believe that the current behaviour dealing with sending whitespace only lines is broken when dealing with sending input that contains newlines. This has been fairly embarrassing in the past when pasting code into irc, for example, and I know it's struck some other people :-) I'm proposing the following patch, which will change the behaviour to allow switching between sending no whitespace-only lines, sending only whitespace-only lines that are not the beginning or ending, and sending every whitespace-only line, with it defaulting to the second case. (I suppose ideally it would collapse together multiple leading or trailing lines, but the code does not currently do so ). I'm asking for opinions as to whether all three of those options should be present, whether more should be added, and if so, what the default would be. (I don't foresee a tremendous use for the 'middle behaviour myself (I plan on setting it to nil and keeping it there), but some others on the channel thought it'd be useful, and be a reasonable default). Depending on feedback, I'll probably commit this tomorrow. Index: erc.el =================================================================== RCS file: /cvsroot/erc/erc/erc.el,v retrieving revision 1.702 diff -r1.702 erc.el 157,160c157,167 < (defcustom erc-send-whitespace-lines nil < "If set to non-nil, send lines consisting of only whitespace." < :group 'erc < :type 'boolean) --- > (defcustom erc-send-whitespace-lines 'middle > "Set whether erc will send user lines that are completely whitespace. > If t, send all whitespace-only lines; if 'middle, only > send non leading/terminal whitespace-only lines. If nil, skip over > every whitespace-only line. Lines that are not sent will be warned > about, if erc-warn-about-blank-lines is set. " > :group 'erc > :type '(choice (const :tag "Always send whitespace lines" t) > (const :tag "Send whitespace lines in the middle of a message" middle) > (const :tag "Never send all-whitespace lines" nil))) > 5762a5770 > 5768,5781c5776,5795 < (cond < ;; Ignore empty input < ((if erc-send-whitespace-lines < (string= input "") < (string-match "\\`[ \t\r\f\n]*\\'" input)) < (when erc-warn-about-blank-lines < (message "Blank line - ignoring...") < (beep)) < nil) < (t < (let ((str input)) < (setq erc-send-this t) < (setq erc-insert-this t) < (run-hook-with-args 'erc-send-pre-hook input) --- > (let ((str input) > (rv nil)) > (setq erc-send-this t) > (setq erc-insert-this t) > (run-hook-with-args 'erc-send-pre-hook input) > > (let* ((lines (split-string str "\n")) > (interpet-commands (= (length lines) 1))) > (loop for (line next-line) on lines for not-first-line = nil then t > if (or (not (string-match "\\`[ \t\r\f\n]*\\'" line)) > (eq t erc-send-whitespace-lines) > (and (eq 'middle erc-send-whitespace-lines) not-first-line (not (null next-line)))) > do (erc-send-single-line line interpet-commands erc-send-this erc-insert-this) > (setq rv t) > else > if erc-warn-about-blank-lines > do (message "Blank line - ignoring...") > (beep) > finally return rv)))) > 5783,5795d5796 < (if (string-match "\n" str) < (mapc < (lambda (line) < (erc-send-single-line line < nil < erc-send-this < erc-insert-this)) < (split-string str "\n")) < (erc-send-single-line str < t < erc-send-this < erc-insert-this)) < t)))) -- I'm awfully glad I'm a Beta, because I don't work so hard. |