unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Antipov <dmantipov@yandex.ru>
To: emacs-devel@gnu.org
Subject: [PATCH] user/group completion for dired
Date: Wed, 21 Sep 2011 11:35:36 +0400	[thread overview]
Message-ID: <4E7993C8.6010609@yandex.ru> (raw)

[-- Attachment #1: Type: text/plain, Size: 67 bytes --]

Hello,

there is a simple user/group completion for dired.

Dmitry

[-- Attachment #2: user_group_completion.patch --]
[-- Type: text/plain, Size: 4684 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 07:19:33 +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,43 @@
   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.
+On UNIX systems, those are user names listed in /etc/passwd file.
+On other systems, this function always returns nil.  */)
+     (void)
+{
+  Lisp_Object users = Qnil;
+#if defined(HAVE_GETPWENT) && defined(HAVE_ENDPWENT)
+  struct passwd *pw;
+
+  while ((pw = getpwent ()))
+    users = Fcons (build_string (pw->pw_name), users);
+
+  endpwent ();
+#endif
+  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.
+On UNIX systems, those are user group names listed in /etc/group file.
+On other systems, this function always returns nil.  */)
+     (void)
+{
+  Lisp_Object groups = Qnil;
+#if defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT)
+  struct group *gr;
+
+  while ((gr = getgrent ()))
+    groups = Fcons (build_string (gr->gr_name), groups);
+
+  endgrent ();
+#endif
+  return groups;
+}
+
 void
 syms_of_dired (void)
 {
@@ -1031,6 +1070,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.


             reply	other threads:[~2011-09-21  7:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-21  7:35 Dmitry Antipov [this message]
2011-09-21  8:49 ` [PATCH] user/group completion for dired 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
2011-09-21 17:40         ` Glenn Morris
2011-09-21 20:22           ` Juri Linkov
2011-09-21 15:27     ` 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

  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=4E7993C8.6010609@yandex.ru \
    --to=dmantipov@yandex.ru \
    --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 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).