2006-01-29 13:08:58 +00:00
|
|
|
;;; erc-autoaway.el --- Provides autoaway for ERC
|
|
|
|
|
2020-01-01 00:19:43 +00:00
|
|
|
;; Copyright (C) 2002-2004, 2006-2020 Free Software Foundation, Inc.
|
2006-01-29 13:08:58 +00:00
|
|
|
|
|
|
|
;; Author: Jorgen Schaefer <forcer@forcix.cx>
|
2020-01-18 02:45:10 +00:00
|
|
|
;; Maintainer: Amin Bandali <mab@gnu.org>
|
Update ERC module URLs
* lisp/erc/erc-autoaway.el, lisp/erc/erc-button.el,
lisp/erc/erc-compat.el, lisp/erc/erc-fill.el, lisp/erc/erc-imenu.el,
lisp/erc/erc-join.el, lisp/erc/erc-lang.el, lisp/erc/erc-match.el,
lisp/erc/erc-pcomplete.el, lisp/erc/erc-ring.el,
lisp/erc/erc-spelling.el, lisp/erc/erc-stamp.el,
lisp/erc/erc-track.el: Update URL to friendlier form, over https.
* lisp/erc/erc-ibuffer.el: Remove URL to nonexistent page.
* lisp/erc/erc-list.el, lisp/erc/erc-log.el, lisp/erc/erc-notify.el,
lisp/erc/erc-replace.el, lisp/erc/erc-services.el,
lisp/erc/erc-sound.el, lisp/erc/erc-speedbar.el,
lisp/erc/erc-truncate.el: Add URL to corresponding EmacsWiki page.
2020-01-24 06:09:43 +00:00
|
|
|
;; URL: https://www.emacswiki.org/emacs/ErcAutoAway
|
2006-01-29 13:08:58 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 03:36:21 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2006-01-29 13:08:58 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 03:36:21 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2006-01-29 13:08:58 +00:00
|
|
|
|
|
|
|
;; 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
|
2017-09-13 22:52:52 +00:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2006-01-29 13:08:58 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; TODO:
|
|
|
|
;; - Legacy names: erc-auto-discard-away, erc-auto-set-away
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'erc)
|
|
|
|
|
|
|
|
(defgroup erc-autoaway nil
|
|
|
|
"Set yourself automatically away after some idletime and set
|
|
|
|
yourself back when you type something."
|
|
|
|
:group 'erc)
|
|
|
|
|
|
|
|
(defvar erc-autoaway-idletimer nil
|
|
|
|
"The Emacs idletimer.
|
2019-11-11 18:30:13 +00:00
|
|
|
This is only used when `erc-autoaway-idle-method' is set to `emacs'.")
|
2006-01-29 13:08:58 +00:00
|
|
|
|
2007-04-01 13:36:38 +00:00
|
|
|
(defvar erc-autoaway-last-sent-time (erc-current-time)
|
|
|
|
"The last time the user sent something.")
|
|
|
|
|
|
|
|
(defvar erc-autoaway-caused-away nil
|
|
|
|
"Indicates whether this module was responsible for setting the
|
|
|
|
user's away status.")
|
|
|
|
|
2008-06-07 02:35:02 +00:00
|
|
|
(defvar erc-autoaway-idle-seconds)
|
2007-04-01 13:36:38 +00:00
|
|
|
|
|
|
|
(defun erc-autoaway-reestablish-idletimer ()
|
|
|
|
"Reestablish the Emacs idletimer.
|
2019-11-11 18:30:13 +00:00
|
|
|
If `erc-autoaway-idle-method' is `emacs', you must call this
|
2007-04-01 13:36:38 +00:00
|
|
|
function each time you change `erc-autoaway-idle-seconds'."
|
|
|
|
(interactive)
|
|
|
|
(when erc-autoaway-idletimer
|
|
|
|
(erc-cancel-timer erc-autoaway-idletimer))
|
|
|
|
(setq erc-autoaway-idletimer
|
|
|
|
(run-with-idle-timer erc-autoaway-idle-seconds
|
|
|
|
t
|
|
|
|
'erc-autoaway-set-away
|
|
|
|
erc-autoaway-idle-seconds)))
|
|
|
|
|
|
|
|
(defun erc-autoaway-some-server-buffer ()
|
|
|
|
"Return some ERC server buffer if its connection is alive.
|
|
|
|
If none is found, return nil."
|
|
|
|
(car (erc-buffer-list #'erc-open-server-buffer-p)))
|
|
|
|
|
|
|
|
(defun erc-autoaway-insinuate-maybe (&optional server &rest ignored)
|
|
|
|
"Add autoaway reset function to `post-command-hook' if at least one
|
|
|
|
ERC process is alive.
|
|
|
|
|
2019-11-11 18:30:13 +00:00
|
|
|
This is used when `erc-autoaway-idle-method' is `user'."
|
2007-04-01 13:36:38 +00:00
|
|
|
(when (or server (erc-autoaway-some-server-buffer))
|
|
|
|
(add-hook 'post-command-hook 'erc-autoaway-reset-idle-user)))
|
|
|
|
|
|
|
|
(defun erc-autoaway-remove-maybe (&rest ignored)
|
|
|
|
"Remove the autoaway reset function from `post-command-hook' if
|
|
|
|
no ERC process is alive.
|
|
|
|
|
2019-11-11 18:30:13 +00:00
|
|
|
This is used when `erc-autoaway-idle-method' is `user'."
|
2007-04-01 13:36:38 +00:00
|
|
|
(unless (erc-autoaway-some-server-buffer)
|
|
|
|
(remove-hook 'post-command-hook 'erc-autoaway-reset-idle-user)))
|
|
|
|
|
Put most erc autoloads in a dedicated file erc-loaddefs.el
These are features that are only useful after erc.el is loaded.
* lisp/erc/erc.el (top-level): Load erc-loaddefs.
* lisp/erc/erc-autoaway.el, lisp/erc/erc-button.el:
* lisp/erc/erc-capab.el, lisp/erc/erc-compat.el:
* lisp/erc/erc-dcc.el, lisp/erc/erc-desktop-notifications.el:
* lisp/erc/erc-ezbounce.el, lisp/erc/erc-fill.el:
* lisp/erc/erc-identd.el, lisp/erc/erc-imenu.el:
* lisp/erc/erc-join.el, lisp/erc/erc-list.el, lisp/erc/erc-log.el:
* lisp/erc/erc-match.el, lisp/erc/erc-menu.el:
* lisp/erc/erc-netsplit.el, lisp/erc/erc-notify.el:
* lisp/erc/erc-page.el, lisp/erc/erc-pcomplete.el:
* lisp/erc/erc-replace.el, lisp/erc/erc-ring.el:
* lisp/erc/erc-services.el, lisp/erc/erc-sound.el:
* lisp/erc/erc-speedbar.el, lisp/erc/erc-spelling.el:
* lisp/erc/erc-stamp.el, lisp/erc/erc-track.el:
* lisp/erc/erc-truncate.el, lisp/erc/erc-xdcc.el:
Set generated-autoload-file to "erc-loaddefs.el".
2017-11-29 02:16:02 +00:00
|
|
|
;;;###autoload(autoload 'erc-autoaway-mode "erc-autoaway")
|
2006-01-29 13:08:58 +00:00
|
|
|
(define-erc-module autoaway nil
|
|
|
|
"In ERC autoaway mode, you can be set away automatically.
|
|
|
|
If `erc-auto-set-away' is set, then you will be set away after
|
|
|
|
the number of seconds specified in `erc-autoaway-idle-seconds'.
|
|
|
|
|
|
|
|
There are several kinds of being idle:
|
|
|
|
|
2006-07-14 02:29:50 +00:00
|
|
|
User idle time measures how long you have not been sending any
|
|
|
|
commands to Emacs. This is the default.
|
2006-01-29 13:08:58 +00:00
|
|
|
|
|
|
|
Emacs idle time measures how long Emacs has been idle. This is
|
|
|
|
currently not useful, since Emacs is non-idle when it handles
|
2006-07-14 02:29:50 +00:00
|
|
|
ping-pong with IRC servers. See `erc-autoaway-idle-method'
|
|
|
|
for more information.
|
2006-01-29 13:08:58 +00:00
|
|
|
|
2006-07-14 02:29:50 +00:00
|
|
|
IRC idle time measures how long since you last sent something (see
|
|
|
|
`erc-autoaway-last-sent-time').
|
2006-01-29 13:08:58 +00:00
|
|
|
|
|
|
|
If `erc-auto-discard-away' is set, then typing anything, will
|
|
|
|
set you no longer away.
|
|
|
|
|
|
|
|
Related variables: `erc-public-away-p' and `erc-away-nickname'."
|
|
|
|
;; Enable:
|
2006-07-14 02:29:50 +00:00
|
|
|
((when (boundp 'erc-autoaway-idle-method)
|
2007-04-01 13:36:38 +00:00
|
|
|
(add-hook 'erc-connect-pre-hook 'erc-autoaway-reset-indicators)
|
|
|
|
(setq erc-autoaway-last-sent-time (erc-current-time))
|
2006-07-14 02:29:50 +00:00
|
|
|
(cond
|
|
|
|
((eq erc-autoaway-idle-method 'irc)
|
|
|
|
(add-hook 'erc-send-completed-hook 'erc-autoaway-reset-idle-irc)
|
|
|
|
(add-hook 'erc-server-001-functions 'erc-autoaway-reset-idle-irc))
|
|
|
|
((eq erc-autoaway-idle-method 'user)
|
2007-04-01 13:36:38 +00:00
|
|
|
(add-hook 'erc-after-connect 'erc-autoaway-insinuate-maybe)
|
|
|
|
(add-hook 'erc-disconnected-hook 'erc-autoaway-remove-maybe)
|
|
|
|
(erc-autoaway-insinuate-maybe))
|
2006-07-14 02:29:50 +00:00
|
|
|
((eq erc-autoaway-idle-method 'emacs)
|
|
|
|
(erc-autoaway-reestablish-idletimer)))
|
|
|
|
(add-hook 'erc-timer-hook 'erc-autoaway-possibly-set-away)
|
|
|
|
(add-hook 'erc-server-305-functions 'erc-autoaway-reset-indicators)))
|
2006-01-29 13:08:58 +00:00
|
|
|
;; Disable:
|
2006-07-14 02:29:50 +00:00
|
|
|
((when (boundp 'erc-autoaway-idle-method)
|
2007-04-01 13:36:38 +00:00
|
|
|
(remove-hook 'erc-connect-pre-hook 'erc-autoaway-reset-indicators)
|
2006-07-14 02:29:50 +00:00
|
|
|
(cond
|
|
|
|
((eq erc-autoaway-idle-method 'irc)
|
|
|
|
(remove-hook 'erc-send-completed-hook 'erc-autoaway-reset-idle-irc)
|
|
|
|
(remove-hook 'erc-server-001-functions 'erc-autoaway-reset-idle-irc))
|
|
|
|
((eq erc-autoaway-idle-method 'user)
|
2007-04-01 13:36:38 +00:00
|
|
|
(remove-hook 'post-command-hook 'erc-autoaway-reset-idle-user)
|
|
|
|
(remove-hook 'erc-after-connect 'erc-autoaway-insinuate-maybe)
|
|
|
|
(remove-hook 'erc-disconnected-hook 'erc-autoaway-remove-maybe))
|
2006-07-14 02:29:50 +00:00
|
|
|
((eq erc-autoaway-idle-method 'emacs)
|
|
|
|
(erc-cancel-timer erc-autoaway-idletimer)
|
|
|
|
(setq erc-autoaway-idletimer nil)))
|
|
|
|
(remove-hook 'erc-timer-hook 'erc-autoaway-possibly-set-away)
|
|
|
|
(remove-hook 'erc-server-305-functions 'erc-autoaway-reset-indicators))))
|
|
|
|
|
|
|
|
(defcustom erc-autoaway-idle-method 'user
|
2012-04-09 13:05:48 +00:00
|
|
|
"The method used to determine how long you have been idle.
|
2019-11-11 18:30:13 +00:00
|
|
|
If `user', the time of the last command sent to Emacs is used.
|
|
|
|
If `emacs', the idle time in Emacs is used.
|
|
|
|
If `irc', the time of the last IRC command is used.
|
2006-07-14 02:29:50 +00:00
|
|
|
|
|
|
|
The time itself is specified by `erc-autoaway-idle-seconds'.
|
|
|
|
|
|
|
|
See `erc-autoaway-mode' for more information on the various
|
|
|
|
definitions of being idle."
|
|
|
|
:group 'erc-autoaway
|
|
|
|
:type '(choice (const :tag "User idle time" user)
|
|
|
|
(const :tag "Emacs idle time" emacs)
|
|
|
|
(const :tag "Last IRC action" irc))
|
|
|
|
:set (lambda (sym val)
|
2007-04-01 13:36:38 +00:00
|
|
|
(if erc-autoaway-mode
|
|
|
|
(progn
|
|
|
|
(erc-autoaway-disable)
|
|
|
|
(set sym val)
|
|
|
|
(erc-autoaway-enable))
|
|
|
|
(set sym val))))
|
2006-01-29 13:08:58 +00:00
|
|
|
|
|
|
|
(defcustom erc-auto-set-away t
|
2012-04-09 13:05:48 +00:00
|
|
|
"If non-nil, set away after `erc-autoaway-idle-seconds' seconds of idling.
|
2006-01-29 13:08:58 +00:00
|
|
|
ERC autoaway mode can set you away when you idle, and set you no
|
|
|
|
longer away when you type something. This variable controls whether
|
|
|
|
you will be set away when you idle. See `erc-auto-discard-away' for
|
|
|
|
the other half."
|
|
|
|
:group 'erc-autoaway
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
|
|
(defcustom erc-auto-discard-away t
|
2012-04-09 13:05:48 +00:00
|
|
|
"If non-nil, sending anything when away automatically discards away state.
|
2006-01-29 13:08:58 +00:00
|
|
|
ERC autoaway mode can set you away when you idle, and set you no
|
|
|
|
longer away when you type something. This variable controls whether
|
|
|
|
you will be set no longer away when you type something. See
|
|
|
|
`erc-auto-set-away' for the other half.
|
|
|
|
See also `erc-autoaway-no-auto-discard-regexp'."
|
|
|
|
:group 'erc-autoaway
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
|
|
(defcustom erc-autoaway-no-auto-discard-regexp "^/g?away.*$"
|
2012-04-09 13:05:48 +00:00
|
|
|
"Input that matches this will not automatically discard away status.
|
2006-01-29 13:08:58 +00:00
|
|
|
See `erc-auto-discard-away'."
|
|
|
|
:group 'erc-autoaway
|
|
|
|
:type 'regexp)
|
|
|
|
|
|
|
|
(defcustom erc-autoaway-idle-seconds 1800
|
2012-04-09 13:05:48 +00:00
|
|
|
"Number of seconds after which ERC will set you automatically away.
|
2006-01-29 13:08:58 +00:00
|
|
|
If you are changing this variable using lisp instead of customizing it,
|
|
|
|
you have to run `erc-autoaway-reestablish-idletimer' afterwards."
|
|
|
|
:group 'erc-autoaway
|
|
|
|
:set (lambda (sym val)
|
|
|
|
(set-default sym val)
|
2006-07-14 02:29:50 +00:00
|
|
|
(when (eq erc-autoaway-idle-method 'emacs)
|
2006-01-29 13:08:58 +00:00
|
|
|
(erc-autoaway-reestablish-idletimer)))
|
|
|
|
:type 'number)
|
|
|
|
|
|
|
|
(defcustom erc-autoaway-message
|
|
|
|
"I'm gone (autoaway after %i seconds of idletime)"
|
2012-04-09 13:05:48 +00:00
|
|
|
"Message ERC will use when setting you automatically away.
|
2006-07-14 02:29:50 +00:00
|
|
|
It is used as a `format' string with the argument of the idletime
|
|
|
|
in seconds."
|
2006-01-29 13:08:58 +00:00
|
|
|
:group 'erc-autoaway
|
|
|
|
:type 'string)
|
|
|
|
|
2006-07-14 02:29:50 +00:00
|
|
|
(defun erc-autoaway-reset-idle-user (&rest stuff)
|
|
|
|
"Reset the stored user idle time.
|
|
|
|
This is one global variable since a user talking on one net can
|
|
|
|
talk on another net too."
|
|
|
|
(when erc-auto-discard-away
|
2007-04-01 13:36:38 +00:00
|
|
|
(erc-autoaway-set-back #'erc-autoaway-remove-maybe))
|
2006-07-14 02:29:50 +00:00
|
|
|
(setq erc-autoaway-last-sent-time (erc-current-time)))
|
|
|
|
|
|
|
|
(defun erc-autoaway-reset-idle-irc (line &rest stuff)
|
|
|
|
"Reset the stored IRC idle time.
|
|
|
|
This is one global variable since a user talking on one net can
|
|
|
|
talk on another net too."
|
2006-01-29 13:08:58 +00:00
|
|
|
(when (and erc-auto-discard-away
|
|
|
|
(stringp line)
|
|
|
|
(not (string-match erc-autoaway-no-auto-discard-regexp line)))
|
2006-07-14 02:29:50 +00:00
|
|
|
(erc-autoaway-set-back))
|
2006-01-29 13:08:58 +00:00
|
|
|
(setq erc-autoaway-last-sent-time (erc-current-time)))
|
|
|
|
|
2007-04-01 13:36:38 +00:00
|
|
|
(defun erc-autoaway-set-back (&optional none-alive-func)
|
|
|
|
"Discard the away state globally.
|
|
|
|
|
|
|
|
NONE-ALIVE-FUNC is the function to call if no ERC processes are alive."
|
|
|
|
(let ((server-buffer (erc-autoaway-some-server-buffer)))
|
|
|
|
(if (and erc-autoaway-caused-away
|
|
|
|
(buffer-live-p server-buffer)
|
|
|
|
(with-current-buffer server-buffer erc-away))
|
|
|
|
(erc-cmd-GAWAY "")
|
|
|
|
(when none-alive-func (funcall none-alive-func)))))
|
|
|
|
|
|
|
|
(defun erc-autoaway-some-open-server-buffer ()
|
|
|
|
"Return some ERC server buffer if its connection is alive and the
|
|
|
|
user is not away.
|
|
|
|
If none is found, return nil."
|
|
|
|
(car (erc-buffer-list (lambda ()
|
|
|
|
(and (erc-open-server-buffer-p)
|
|
|
|
(not erc-away))))))
|
2006-01-29 13:08:58 +00:00
|
|
|
|
|
|
|
(defun erc-autoaway-possibly-set-away (current-time)
|
|
|
|
"Set autoaway when `erc-auto-set-away' is true and the idletime is
|
|
|
|
exceeds `erc-autoaway-idle-seconds'."
|
|
|
|
;; A test for (erc-server-process-alive) is not necessary, because
|
|
|
|
;; this function is called from `erc-timer-hook', which is called
|
|
|
|
;; whenever the server sends something to the client.
|
2007-11-29 22:36:38 +00:00
|
|
|
(when (and erc-server-connected
|
|
|
|
erc-auto-set-away
|
2006-11-20 06:50:29 +00:00
|
|
|
(not erc-autoaway-caused-away)
|
2007-04-01 13:36:38 +00:00
|
|
|
(erc-autoaway-some-open-server-buffer))
|
2006-01-29 13:08:58 +00:00
|
|
|
(let ((idle-time (erc-time-diff erc-autoaway-last-sent-time
|
|
|
|
current-time)))
|
|
|
|
(when (>= idle-time erc-autoaway-idle-seconds)
|
|
|
|
(erc-display-message
|
|
|
|
nil 'notice nil
|
|
|
|
(format "Setting automatically away after %i seconds of idle-time"
|
|
|
|
idle-time))
|
2007-04-01 13:36:38 +00:00
|
|
|
(erc-autoaway-set-away idle-time t)))))
|
|
|
|
|
|
|
|
(defun erc-autoaway-set-away (idle-time &optional notest)
|
|
|
|
"Set the away state globally.
|
2006-01-29 13:08:58 +00:00
|
|
|
|
2007-04-01 13:36:38 +00:00
|
|
|
If NOTEST is specified, do not check to see whether there is an
|
2011-11-14 23:59:56 +00:00
|
|
|
active server buffer available."
|
2006-01-29 13:08:58 +00:00
|
|
|
;; Note that the idle timer runs, even when Emacs is inactive. In
|
|
|
|
;; order to prevent flooding when we connect, we test for an
|
|
|
|
;; existing process.
|
2007-04-01 13:36:38 +00:00
|
|
|
(when (or notest (erc-autoaway-some-open-server-buffer))
|
2006-07-14 02:29:50 +00:00
|
|
|
(setq erc-autoaway-caused-away t)
|
2015-08-31 22:10:07 +00:00
|
|
|
(erc-cmd-GAWAY (format-message erc-autoaway-message idle-time))))
|
2006-01-29 13:08:58 +00:00
|
|
|
|
2006-07-14 02:29:50 +00:00
|
|
|
(defun erc-autoaway-reset-indicators (&rest stuff)
|
|
|
|
"Reset indicators used by the erc-autoaway module."
|
|
|
|
(setq erc-autoaway-last-sent-time (erc-current-time))
|
|
|
|
(setq erc-autoaway-caused-away nil))
|
|
|
|
|
2006-01-29 13:08:58 +00:00
|
|
|
(provide 'erc-autoaway)
|
|
|
|
|
|
|
|
;;; erc-autoaway.el ends here
|
|
|
|
;;
|
|
|
|
;; Local Variables:
|
Put most erc autoloads in a dedicated file erc-loaddefs.el
These are features that are only useful after erc.el is loaded.
* lisp/erc/erc.el (top-level): Load erc-loaddefs.
* lisp/erc/erc-autoaway.el, lisp/erc/erc-button.el:
* lisp/erc/erc-capab.el, lisp/erc/erc-compat.el:
* lisp/erc/erc-dcc.el, lisp/erc/erc-desktop-notifications.el:
* lisp/erc/erc-ezbounce.el, lisp/erc/erc-fill.el:
* lisp/erc/erc-identd.el, lisp/erc/erc-imenu.el:
* lisp/erc/erc-join.el, lisp/erc/erc-list.el, lisp/erc/erc-log.el:
* lisp/erc/erc-match.el, lisp/erc/erc-menu.el:
* lisp/erc/erc-netsplit.el, lisp/erc/erc-notify.el:
* lisp/erc/erc-page.el, lisp/erc/erc-pcomplete.el:
* lisp/erc/erc-replace.el, lisp/erc/erc-ring.el:
* lisp/erc/erc-services.el, lisp/erc/erc-sound.el:
* lisp/erc/erc-speedbar.el, lisp/erc/erc-spelling.el:
* lisp/erc/erc-stamp.el, lisp/erc/erc-track.el:
* lisp/erc/erc-truncate.el, lisp/erc/erc-xdcc.el:
Set generated-autoload-file to "erc-loaddefs.el".
2017-11-29 02:16:02 +00:00
|
|
|
;; generated-autoload-file: "erc-loaddefs.el"
|
2006-01-29 13:08:58 +00:00
|
|
|
;; End:
|