unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Kelvin White <kelvin.white77@gmail.com>
Cc: Lawrence Mitchell <wence@gmx.li>, Michael Olson <mwolson@gnu.org>,
	17755@debbugs.gnu.org, mlang@delysid.org,
	Diane Murray <disumu@x3y2z1.net>, Alex Schroeder <alex@gnu.org>,
	Julien Danjou <julien@danjou.info>,
	Francis Litterio <franl@users.sourceforge.net>,
	Jorgen Schaefer <forcer@users.sourceforge.net>
Subject: bug#17755: 24.3; ERC user mode support
Date: Tue, 17 Jun 2014 12:03:52 -0400	[thread overview]
Message-ID: <jwvmwdb4l1x.fsf-monnier+emacsbugs@gnu.org> (raw)
In-Reply-To: <CAG-q9=ahVBNq=RnvK7JizgKth2ON53ZiLa41u1K5wychzm696Q@mail.gmail.com> (Kelvin White's message of "Wed, 11 Jun 2014 07:45:12 -0400")

> Here is the patch to add this feature

Thanks, here are some comments on it.  I wish someone who has worked on
ERC could say something.  I never use(d) IRC and have hence no clue what is
a "user mode prefix", for example.

> ***************
> *** 1244,1250 ****
>                          (erc-format-message
>                           'JOIN ?n nick ?u login ?h host ?c chnl))))))
>             (when buffer (set-buffer buffer))
> !           (erc-update-channel-member chnl nick nick t nil nil host login)
>             ;; on join, we want to stay in the new channel buffer
>             ;;(set-buffer ob)
>             (erc-display-message parsed nil buffer str))))))
> --- 1244,1250 ----
>                          (erc-format-message
>                           'JOIN ?n nick ?u login ?h host ?c chnl))))))
>             (when buffer (set-buffer buffer))
> !           (erc-update-channel-member chnl nick nick t nil nil nil nil nil host login)
>             ;; on join, we want to stay in the new channel buffer
>             ;;(set-buffer ob)
>             (erc-display-message parsed nil buffer str))))))

In my opinion, erc-update-channel-member had too many arguments already.
Maybe some of these args should be combined into an erc-channel-user object?

> + (defsubst erc-channel-user-owner-p (nick)
> +   "Return t if NICK is an owner of the current channel."

Usually we say "non-nil" rather than "t", unless the callers need to
rely on the return value being t rather than some other non-nil value.

> + (defface erc-nick-prefix-face '((t :weight bold))
> +   "ERC face used for user mode prefix."
> +   :group 'erc-faces)
> +
> + (defface erc-my-nick-prefix-face '((t :weight bold))
> +   "ERC face used for my user mode prefix."
> +   :group 'erc-faces)

Try to use the :inherit property at least to link those two (so users
who just want to change the two without making them different only need
to change one of the two) and ideally by inheriting from some other face.

> + (defun erc-get-user-mode-prefix (user)
> +   (when user
> +     (cond ((erc-channel-user-voice-p user) "+")
> +           ((erc-channel-user-half-op-p user) "%")
> +           ((erc-channel-user-op-p user) "@")
> +           ((erc-channel-user-admin-p user) "&")
> +           ((erc-channel-user-owner-p user) "~")
> +           (t ""))))

Here I assume there's some kind of logic or convention.  If not, maybe
it would be appropriate to do something like add some `help-echo'
property to those extra chars?

One more thing: the above suggests that maybe
voice/halfop/op/admin/owner are mutually exclusive.  Is that the case?
Could these be collapsed into a single element which could have values
`voice', `halfop', `op', `admin', or `owner' (or nil)?

>   (defun erc-format-@nick (&optional user channel-data)
>     "Format the nickname of USER showing if USER is an operator or has voice.
>   Operators have \"@\" and users with voice have \"+\" as a prefix.
>   Use CHANNEL-DATA to determine op and voice status.
>   See also `erc-format-nick-function'."
>     (when user
> !     (let ((nick (erc-server-user-nickname user)))
> !       (concat (erc-propertize (erc-get-user-mode-prefix nick) 'face 'erc-nick-prefix-face) nick))))

Please try to stay with 80 columns.

BTW, IIUC, ERC is not distributed separately from Emacs any more, so we
don't need to use compatibility crutches like erc-propertize any more
(tho it's fine to use it as well for now, and it could be removed "all at
once" in another patch).

> !                "(ov)@+"))
[...]
> !                  "(qaohv)~&@%+"))

Yay!  Magic!

> !   (let (prefix op-ch voice-ch names name op voice)
>       (setq prefix (erc-parse-prefix))
> !     (setq op-ch (cdr (assq ?o prefix))
> !         voice-ch (cdr (assq ?v prefix)))

this should have been

      (let* ((prefix (erc-parse-prefix))
             (op-ch (cdr (assq ?o prefix)))
             (voice-ch (cdr (assq ?v prefix)))
             names name op voice)

Which is both cleaner and faster.

So when you change such code, you can take advantage of the change to
try and reduce occurrences of those "let-without-init followed by setq".

> --- 4763,4820 ----
>             (if (rassq (elt item 0) prefix)
>                 (cond ((= (length item) 1)
>                        (setq updatep nil))
> +                     ((eq (elt item 0) voice-ch)
> +                      (setq name (substring item 1)
> +                            op 'off
> +                            voice 'on
> +                            halfop 'off
> +                            admin 'off
> +                            owner 'off))
> +                     ((eq (elt item 0) hop-ch)
> +                      (setq name (substring item 1)
> +                            op 'off
> +                            voice 'off
> +                            halfop 'on
> +                            admin 'off
> +                            owner 'off))
>                       ((eq (elt item 0) op-ch)
>                        (setq name (substring item 1)
>                              op 'on
> !                            voice 'off
> !                            halfop 'off
> !                            admin 'off
> !                            owner 'off))
> !                     ((eq (elt item 0) adm-ch)
> !                      (setq name (substring item 1)
> !                            op 'off
> !                            voice 'off
> !                            halfop 'off
> !                            admin 'on
> !                            owner 'off))
> !                     ((eq (elt item 0) own-ch)
>                        (setq name (substring item 1)
>                              op 'off
> !                            voice 'off
> !                            halfop 'off
> !                            admin 'off
> !                            owner 'on))
>                       (t (setq name (substring item 1)
>                                op 'off
> !                              voice 'off
> !                              halfop 'off
> !                              admin 'off
> !                              owner 'off)))

This also makes it sound like those op/voice/admin/owner are mutually
exclusive and should be combined into a single element.

Otherwise, please simplify the code with:

   (setq op 'off voice 'off halfop 'off admin 'off owner 'off)
   (cond
    ((eq (elt item 0) voice-ch)
     (setq name (substring item 1)
           voice 'on))
    [...])

> +           (when (and voice
> +                      (not (eq (erc-channel-user-voice cuser) voice)))
> +             (setq changed t)
> +             (setf (erc-channel-user-voice cuser)
> +                   (cond ((eq voice 'on) t)
> +                         ((eq voice 'off) nil)
> +                         (t voice))))

Won't this cause `changed' to "always" be set to t, since
(erc-channel-user-voice cuser) will never be `on' or `off' and hence
never be equal to `voice'?

Also, instead of using on/off and converting them from&to nil/t, maybe
it would be simpler to use nil/t plus a special value
(e.g. `:unspecified') for the case where the value is simply
not provided.


        Stefan





  reply	other threads:[~2014-06-17 16:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-11 10:34 bug#17755: 24.3; ERC user mode support kelvin.white77
2014-06-11 11:45 ` Kelvin White
2014-06-17 16:03   ` Stefan Monnier [this message]
2014-06-18 14:40     ` Kelvin White
2014-06-18 16:08       ` Kelvin White
2014-06-18 18:32       ` Stefan Monnier
2014-06-18 18:51         ` Kelvin White
2014-10-02 19:31 ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvmwdb4l1x.fsf-monnier+emacsbugs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=17755@debbugs.gnu.org \
    --cc=alex@gnu.org \
    --cc=disumu@x3y2z1.net \
    --cc=forcer@users.sourceforge.net \
    --cc=franl@users.sourceforge.net \
    --cc=julien@danjou.info \
    --cc=kelvin.white77@gmail.com \
    --cc=mlang@delysid.org \
    --cc=mwolson@gnu.org \
    --cc=wence@gmx.li \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).