From: Dmitry Antipov <dmantipov@yandex.ru>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] user/group completion for dired
Date: Wed, 21 Sep 2011 19:54:59 +0400 [thread overview]
Message-ID: <4E7A08D3.8000006@yandex.ru> (raw)
In-Reply-To: <83sjnqrl7d.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 363 bytes --]
On 09/21/2011 07:04 PM, Eli Zaretskii wrote:
> Why let it guess? You can do it with 100% certainty in this case,
> because the encoding of strings provided by the OS is known -- it's
> held in Vlocale_coding_system. See system_process_attributes for an
> example of how to do this.
I've looked through Ffile_attributes() and have made the same thing.
Dmitry
[-- Attachment #2: user_group_completion_2.patch --]
[-- Type: text/plain, Size: 4725 bytes --]
=== modified file 'configure.in'
--- configure.in 2011-09-15 03:01:25 +0000
+++ configure.in 2011-09-21 03:36:38 +0000
@@ -1206,7 +1206,7 @@
linux/version.h sys/systeminfo.h \
stdio_ext.h fcntl.h coff.h pty.h sys/mman.h \
sys/vlimit.h sys/resource.h locale.h sys/_mbstate_t.h \
- sys/utsname.h pwd.h utmp.h dirent.h util.h)
+ sys/utsname.h pwd.h grp.h utmp.h dirent.h util.h)
AC_MSG_CHECKING(if personality LINUX32 can be set)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/personality.h>]], [[personality (PER_LINUX32)]])],
@@ -2730,6 +2730,7 @@
sendto recvfrom getsockopt setsockopt getsockname getpeername \
gai_strerror mkstemp getline getdelim mremap fsync sync \
difftime mempcpy mblen mbrlen posix_memalign \
+getpwent endpwent getgrent endgrent \
cfmakeraw cfsetspeed copysign __executable_start)
dnl Cannot use AC_CHECK_FUNCS
=== modified file 'lisp/dired-aux.el'
--- lisp/dired-aux.el 2011-09-14 15:06:28 +0000
+++ lisp/dired-aux.el 2011-09-21 07:12:38 +0000
@@ -244,8 +244,12 @@
(if (eq op-symbol 'touch)
" (default now): "
": ")))
- (new-attribute (dired-mark-read-string prompt nil op-symbol
- arg files default))
+ (new-attribute (dired-mark-read-string
+ prompt
+ (cond ((eq op-symbol 'chown) (system-users))
+ ((eq op-symbol 'chgrp) (system-groups)))
+ nil op-symbol
+ arg files default))
(operation (concat program " " new-attribute))
failures)
(setq failures
@@ -284,7 +288,7 @@
(match-string 2 modestr)
(match-string 3 modestr)))))
(modes (dired-mark-read-string
- "Change mode of %s to: "
+ "Change mode of %s to: " nil
nil 'chmod arg files default))
num-modes)
(cond ((equal modes "")
@@ -374,7 +378,7 @@
(interactive "P")
(let* ((file-list (dired-get-marked-files t arg))
(command (dired-mark-read-string
- "Print %s with: "
+ "Print %s with: " nil
(mapconcat 'identity
(cons lpr-command
(if (stringp lpr-switches)
@@ -384,8 +388,8 @@
'print arg file-list)))
(dired-run-shell-command (dired-shell-stuff-it command file-list nil))))
-(defun dired-mark-read-string (prompt initial op-symbol arg files
- &optional default-value)
+(defun dired-mark-read-string (prompt collection initial op-symbol
+ arg files &optional default-value)
"Read args for a Dired marked-files command, prompting with PROMPT.
Return the user input (a string).
@@ -399,9 +403,9 @@
user enters empty input, this function returns the empty string,
not DEFAULT-VALUE."
(dired-mark-pop-up nil op-symbol files
- 'read-from-minibuffer
+ 'completing-read
(format prompt (dired-mark-prompt arg files))
- initial nil nil nil default-value))
+ collection nil nil initial nil default-value nil))
\f
;;; Cleaning a directory: flagging some backups for deletion.
=== modified file 'src/dired.c'
--- src/dired.c 2011-09-09 01:06:52 +0000
+++ src/dired.c 2011-09-21 15:41:25 +0000
@@ -27,7 +27,9 @@
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
+#ifdef HAVE_GRP_H
#include <grp.h>
+#endif
#include <errno.h>
#include <unistd.h>
@@ -1014,6 +1016,45 @@
return Fstring_lessp (Fcar (f1), Fcar (f2));
}
\f
+
+DEFUN ("system-users", Fsystem_users, Ssystem_users, 0, 0, 0,
+ doc: /* Return a list of user names currently registered in the system.
+The value may be nil if not supported on this platform. */)
+ (void)
+{
+ Lisp_Object users = Qnil;
+#if defined(HAVE_GETPWENT) && defined(HAVE_ENDPWENT)
+ struct passwd *pw;
+
+ while ((pw = getpwent ()))
+ users = Fcons (DECODE_SYSTEM (build_string (pw->pw_name)), users);
+
+ endpwent ();
+#endif
+ if (EQ (users, Qnil))
+ /* At least current user is always known. */
+ users = Fcons (Vuser_real_login_name, Qnil);
+ return users;
+}
+
+DEFUN ("system-groups", Fsystem_groups, Ssystem_groups, 0, 0, 0,
+ doc: /* Return a list of user group names currently registered in the system.
+The value may be nil if not supported on this platform. */)
+ (void)
+{
+ Lisp_Object groups = Qnil;
+#if defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT)
+ struct group *gr;
+ int length;
+
+ while ((gr = getgrent ()))
+ groups = Fcons (DECODE_SYSTEM (build_string (gr->gr_name)), groups);
+
+ endgrent ();
+#endif
+ return groups;
+}
+
void
syms_of_dired (void)
{
@@ -1031,6 +1072,8 @@
defsubr (&Sfile_name_all_completions);
defsubr (&Sfile_attributes);
defsubr (&Sfile_attributes_lessp);
+ defsubr (&Ssystem_users);
+ defsubr (&Ssystem_groups);
DEFVAR_LISP ("completion-ignored-extensions", Vcompletion_ignored_extensions,
doc: /* Completion ignores file names ending in any string in this list.
next prev parent reply other threads:[~2011-09-21 15:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-21 7:35 [PATCH] user/group completion for dired Dmitry Antipov
2011-09-21 8:49 ` Eli Zaretskii
2011-09-21 9:25 ` Andreas Schwab
2011-09-21 13:59 ` Dmitry Antipov
2011-09-21 15:04 ` Eli Zaretskii
2011-09-21 15:54 ` Dmitry Antipov [this message]
2011-09-21 17:40 ` Glenn Morris
2011-09-21 20:22 ` Juri Linkov
2011-09-22 3:57 ` bug#7900: [PATCH] Dmitry Antipov
2011-09-21 15:27 ` [PATCH] user/group completion for dired Juanma Barranquero
2011-09-21 20:21 ` Juri Linkov
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E7A08D3.8000006@yandex.ru \
--to=dmantipov@yandex.ru \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/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 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.