Hi Eric,
About our previous discussion about having an option to disable some
semantic working messages, WDYT of extending working to provide a
general mechanism for that?
Following is a quick and simple implementation based on message levels
by channels. Provided we change all calls to `message' by appropriate
calls to one the functions `working-debug', `working-info',
`working-warn', or `working-error' below, it will be easy to customize
which kind of messages to display for a given channel.
Intuitively, semantic messages will be send to the `semantic' channel.
The default behavior I specified for that channel is to display all
messages but info ones.
Thoughts?
David
(define-widget 'working-level-by-channels-widget 'alist
"Widget to display the level of working messages by channels."
:key-type '(symbol :tag "Channel")
:value-type '(choice :tag "Level"
(const debug)
(const info)
(const warning)
(const error))
:tag "Level of working message by channels")
(defcustom working-level-by-channels
'(
(semantic . warning)
)
"*Levels of displayed working messages by channels.
This is an alist of (CHANNEL . LEVEL) elements where CHANNEL is a
symbol identifying a channel and LEVEL is one of the symbol `debug',
`info', `warning' or `error'.
For a given CHANNEL, all messages will be displayed if the `debug'
level is specified. If `info' all messages but debug ones will be
displayed; If `warning' all messages but debug and info ones will be
displayed; and so on.
By default all messages will be displayed when no LEVEL is specified
for a CHANNEL."
:group 'working
:type 'working-level-by-channels-widget)
(defconst working-level-weights
'((error . 8)
(warning . 4)
(info . 2)
(debug . 0))
"Weight of level symbols.")
(defsubst working-level-weight (level)
"Return the weight of LEVEL as an integer."
(let ((weight (assq level working-level-weights)))
(or (cdr weight)
(signal 'wrong-type-argument
(list level working-level-weights)))))
(defsubst working-level-enabled-p (level channel)
"Return non-nil if message LEVEL is enabled for CHANNEL.
That is if such messages will actually be displayed.
See also the option `working-level-by-channels'."
(let ((min-level (cdr (assq channel working-level-by-channels))))
(or (not min-level)
(>= (working-level-weight level)
(working-level-weight min-level)))))
(defsubst working-level-message (channel level &rest args)
"Send a message to CHANNEL at level LEVEL.
If LEVEL is enabled on CHANNEL, ARGS will be passed to the
`working-message' function."
(and (working-level-enabled-p level channel)
;; Maybe using `working-temp-message' would be better?
(apply 'working-message args)))
(defun working-debug (channel &rest args)
"Send a debug message to CHANNEL.
If debug level is enabled on CHANNEL, ARGS will be passed to the
`working-message' function."
(apply 'working-level-message channel 'debug args))
(defun working-error (channel &rest args)
"Send an error message to CHANNEL.
If error level is enabled on CHANNEL, ARGS will be passed to the
`working-message' function."
(apply 'working-level-message channel 'error args))
(defun working-warn (channel &rest args)
"Send a warning message to CHANNEL.
If warning level is enabled on CHANNEL, ARGS will be passed to the
`working-message' function."
(apply 'working-level-message channel 'warning args))
(defun working-info (channel &rest args)
"Send an informational message to CHANNEL.
If info level is enabled on CHANNEL, ARGS will be passed to the
`working-message' function."
(apply 'working-level-message channel 'info args))
|