|
From: lawrence m. <we...@gm...> - 2003-12-06 23:43:38
|
What do people think of factoring out some of the code from
erc-send-current-line into a new function. This allows us to
insert things in an erc buffer correctly, without having to call
erc-send-current-line. Particularly handy for things like
erc-cmd-SAY. This patch is a first stab at it, just pulling out
the (lambda (line) ...) from erc-send-current-line into a
separate function. It's evil, since it relies on let-bound
variables propagating down the call stack, and they may not
always be bound, but it's late, and I haven't looked at it
properly.
Index: erc.el
===================================================================
RCS file: /cvsroot/erc/erc/erc.el,v
retrieving revision 1.586
diff -u -r1.586 erc.el
--- erc.el 6 Dec 2003 22:43:29 -0000 1.586
+++ erc.el 6 Dec 2003 23:40:11 -0000
@@ -2450,7 +2450,8 @@
multiple lines of text."
(if (string-match "^\\s-*$" line)
nil
- (erc-process-input-line line nil t)))
+ (erc-process-input-line line nil t)
+ (erc-insert-line line t)))
(put 'erc-cmd-SAY 'do-not-parse-args t)
(defun erc-cmd-SET (line)
@@ -5777,44 +5778,7 @@
(when erc-show-my-nick
(erc-put-text-property 0 (length nickname) 'face
'erc-nick-default-face nickname))
- (mapc
- (lambda (line)
- (unless (string-match "^\\s-*\n*$" line)
- (if (null erc-insert-this)
- ;; Leave erc-insert-this set to t as much as possible.
- ;; Fran Litterio <franl> has seen erc-insert-this set to
- ;; nil while erc-send-pre-hook is running, which should
- ;; never happen. This may cure it.
- (setq erc-insert-this t)
- (let ((insert-position (point)))
- (if (and (not multiline-p)
- (char-equal (aref line 0) ?/)) ; is it a non-pasted command?
- (if (not erc-hide-prompt)
- (erc-display-prompt nil nil (erc-command-indicator)
- (and (erc-command-indicator)
- 'erc-command-indicator-face)))
- (insert ; ok, it's a privmsg.
- (if erc-show-my-nick
- (concat "<" nickname "> ")
- "> ")))
- (when (string-match "[\n]+$" line) ; remove the \ns at the end.
- (setq line (substring line 0 (match-beginning 0))))
- (erc-put-text-property 0 (length line)
- 'face 'erc-input-face line)
- (insert (erc-interpret-controls line))
- (goto-char (point-max))
- (open-line 1)
- (goto-char (point-max))
- (set-marker (process-mark erc-process) (point))
- (set-marker erc-insert-marker (point))
- (save-excursion
- (save-match-data
- (save-restriction
- (narrow-to-region insert-position (point-max))
- (run-hook-with-args 'erc-send-modify-hook)
- (run-hook-with-args 'erc-send-post-hook))))))
- (erc-process-input-line (concat line "\n") t multiline-p)))
- lines)))
+ (mapc #'erc-insert-line lines)))
;; Go to (point-max), but only if the command left an ERC buffer as the
;; current buffer.
(if (eq major-mode 'erc-mode)
@@ -5827,6 +5791,44 @@
(erc-display-prompt)
(set-buffer-modified-p buffer-modified))
(run-hook-with-args 'erc-send-completed-hook str)))))))
+
+(defun erc-insert-line (line &optional dont-send)
+ (unless (string-match "^\\s-*\n*$" line)
+ (if (null erc-insert-this)
+ ;; Leave erc-insert-this set to t as much as possible.
+ ;; Fran Litterio <franl> has seen erc-insert-this set to
+ ;; nil while erc-send-pre-hook is running, which should
+ ;; never happen. This may cure it.
+ (setq erc-insert-this t)
+ (let ((insert-position (point)))
+ (if (and (not multiline-p)
+ (char-equal (aref line 0) ?/)) ; is it a non-pasted command?
+ (if (not erc-hide-prompt)
+ (erc-display-prompt nil nil (erc-command-indicator)
+ (and (erc-command-indicator)
+ 'erc-command-indicator-face)))
+ (insert ; ok, it's a privmsg.
+ (if erc-show-my-nick
+ (concat "<" nickname "> ")
+ "> ")))
+ (when (string-match "[\n]+$" line) ; remove the \ns at the end.
+ (setq line (substring line 0 (match-beginning 0))))
+ (erc-put-text-property 0 (length line)
+ 'face 'erc-input-face line)
+ (insert (erc-interpret-controls line))
+ (goto-char (point-max))
+ (open-line 1)
+ (goto-char (point-max))
+ (set-marker (process-mark erc-process) (point))
+ (set-marker erc-insert-marker (point))
+ (save-excursion
+ (save-match-data
+ (save-restriction
+ (narrow-to-region insert-position (point-max))
+ (run-hook-with-args 'erc-send-modify-hook)
+ (run-hook-with-args 'erc-send-post-hook))))))
+ (or dont-send
+ (erc-process-input-line (concat line "\n") t multiline-p))))
(defun erc-extract-command-from-line (line)
"Extract command and args from the input LINE.
--
lawrence mitchell <we...@gm...>
|