* [Emacs LISP] Login freenode using ERC with prompt for password only
@ 2012-12-01 9:21 Wenshan Ren
2012-12-01 9:54 ` Pascal J. Bourguignon
0 siblings, 1 reply; 3+ messages in thread
From: Wenshan Ren @ 2012-12-01 9:21 UTC (permalink / raw)
To: help-gnu-emacs
Hello everyone, I am new to Emacs LISP and trying to write a emacs lisp, which hopefully will enable me to login irc without choosing server/port/nick.
After reading "C-h f erc", I end up with
(defun my-erc() (erc :server "irc.freenode.net" :port "6667" :nick "mynickname"))
If I put `:pass "mypassword"` at the end of the list, it works fine. However, I don't want to put my password in .emacs, so I hope Emacs will ask me for password when needed.
With the my-erc function I wrote, erc will login password and I have to identify myself afterwards.
Could you give me some hints on solving this?
Wenshan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Emacs LISP] Login freenode using ERC with prompt for password only
2012-12-01 9:21 [Emacs LISP] Login freenode using ERC with prompt for password only Wenshan Ren
@ 2012-12-01 9:54 ` Pascal J. Bourguignon
2012-12-01 20:52 ` Wenshan Ren
0 siblings, 1 reply; 3+ messages in thread
From: Pascal J. Bourguignon @ 2012-12-01 9:54 UTC (permalink / raw)
To: help-gnu-emacs
Wenshan Ren <renws1990@gmail.com> writes:
> Hello everyone, I am new to Emacs LISP and trying to write a emacs
> lisp, which hopefully will enable me to login irc without choosing
> server/port/nick.
>
> After reading "C-h f erc", I end up with
>
> (defun my-erc() (erc :server "irc.freenode.net" :port "6667" :nick "mynickname"))
>
> If I put `:pass "mypassword"` at the end of the list, it works
> fine. However, I don't want to put my password in .emacs, so I hope
> Emacs will ask me for password when needed.
>
> With the my-erc function I wrote, erc will login password and I have to identify myself afterwards.
>
> Could you give me some hints on solving this?
You could consider storing your irc password in ~/.authinfo, where other
passwords (for news, email, ftp, etc) can also be stored.
(require 'cl)
(defvar *authinfo-file* "~/.authinfo")
(defun password-for-machine-login (machine login)
(cdr (assoc "password"
(find-if (lambda (entry)
(and (string= machine (cdr (assoc "machine" entry)))
(string= login (cdr (assoc "login" entry)))))
(netrc-parse *authinfo-file*)))))
(password-for-machine-login "irc.freenode.net" "pjb")
--> "XXXXXXXX"
or you can ask the password to the user each time (it grows old very
soon):
(defun password-for-machine-login (machine login)
(let ((password-cache nil))
(password-read (format "password for %s at %s ?" login machine))))
(password-for-machine-login "irc.freenode.net" "pjb")
--> "XXXXXXXX"
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Emacs LISP] Login freenode using ERC with prompt for password only
2012-12-01 9:54 ` Pascal J. Bourguignon
@ 2012-12-01 20:52 ` Wenshan Ren
0 siblings, 0 replies; 3+ messages in thread
From: Wenshan Ren @ 2012-12-01 20:52 UTC (permalink / raw)
To: help-gnu-emacs
Thank you so much, your reply really made me better on Emacs Lisp.
I can't understand the first function very well as a beginner, so I modified the second to meet my needs, very trivial, but works :)
(defun myerc ()
(interactive)
(let
((password-cache nil))
(erc
:server "irc.freenode.net"
:port "6667"
:nick "Meatball_py"
:password (password-read (format "password for Meatball at freenode?")))))
Thanks again.
On Saturday, December 1, 2012 8:54:51 PM UTC+11, Pascal J. Bourguignon wrote:
> Wenshan Ren <renws1990@gmail.com> writes:
>
>
>
> > Hello everyone, I am new to Emacs LISP and trying to write a emacs
>
> > lisp, which hopefully will enable me to login irc without choosing
>
> > server/port/nick.
>
> >
>
> > After reading "C-h f erc", I end up with
>
> >
>
> > (defun my-erc() (erc :server "irc.freenode.net" :port "6667" :nick "mynickname"))
>
> >
>
> > If I put `:pass "mypassword"` at the end of the list, it works
>
> > fine. However, I don't want to put my password in .emacs, so I hope
>
> > Emacs will ask me for password when needed.
>
> >
>
> > With the my-erc function I wrote, erc will login password and I have to identify myself afterwards.
>
> >
>
> > Could you give me some hints on solving this?
>
>
>
> You could consider storing your irc password in ~/.authinfo, where other
>
> passwords (for news, email, ftp, etc) can also be stored.
>
>
>
> (require 'cl)
>
> (defvar *authinfo-file* "~/.authinfo")
>
> (defun password-for-machine-login (machine login)
>
> (cdr (assoc "password"
>
> (find-if (lambda (entry)
>
> (and (string= machine (cdr (assoc "machine" entry)))
>
> (string= login (cdr (assoc "login" entry)))))
>
> (netrc-parse *authinfo-file*)))))
>
>
>
> (password-for-machine-login "irc.freenode.net" "pjb")
>
> --> "XXXXXXXX"
>
>
>
>
>
> or you can ask the password to the user each time (it grows old very
>
> soon):
>
>
>
> (defun password-for-machine-login (machine login)
>
> (let ((password-cache nil))
>
> (password-read (format "password for %s at %s ?" login machine))))
>
>
>
> (password-for-machine-login "irc.freenode.net" "pjb")
>
> --> "XXXXXXXX"
>
>
>
> --
>
> __Pascal Bourguignon__ http://www.informatimago.com/
>
> A bad day in () is better than a good day in {}.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-12-01 20:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-01 9:21 [Emacs LISP] Login freenode using ERC with prompt for password only Wenshan Ren
2012-12-01 9:54 ` Pascal J. Bourguignon
2012-12-01 20:52 ` Wenshan Ren
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.