unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] user/group name completion
@ 2008-10-17  6:59 Antipov Dmitry
  0 siblings, 0 replies; only message in thread
From: Antipov Dmitry @ 2008-10-17  6:59 UTC (permalink / raw)
  To: emacs-devel

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

Hello,



this patch introduces a user/group name completion for 'call-interactively'. This

feature may be used, for example, within 'dired-do-chown' and 'dired-do-chgrp'

(although it should be extended to MS and MacOS systems first, BTW).

 

Dmitry


[-- Attachment #2: user_group_completion.patch --]
[-- Type: application/octet-stream, Size: 4546 bytes --]

Index: configure.in
===================================================================
RCS file: /sources/emacs/emacs/configure.in,v
retrieving revision 1.567
diff -u -r1.567 configure.in
--- configure.in	12 Oct 2008 12:47:25 -0000	1.567
+++ configure.in	17 Oct 2008 05:36:37 -0000
@@ -995,7 +995,7 @@
   linux/version.h sys/systeminfo.h termios.h limits.h string.h stdlib.h \
   termcap.h stdio_ext.h fcntl.h strings.h coff.h pty.h sys/mman.h \
   sys/param.h sys/vlimit.h sys/resource.h locale.h sys/_mbstate_t.h \
-  sys/utsname.h pwd.h)
+  sys/utsname.h pwd.h grp.h)
 
 AC_MSG_CHECKING(if personality LINUX32 can be set)
 AC_TRY_COMPILE([#include <sys/personality.h>], [personality (PER_LINUX32)],
@@ -2139,7 +2139,7 @@
 sendto recvfrom getsockopt setsockopt getsockname getpeername \
 gai_strerror mkstemp getline getdelim mremap memmove fsync sync bzero \
 memset memcmp difftime memcpy mempcpy mblen mbrlen posix_memalign \
-cfmakeraw cfsetspeed)
+cfmakeraw cfsetspeed getpwent endpwent getgrent endgrent)
 
 AC_CHECK_HEADERS(sys/un.h)
 
Index: src/callint.c
===================================================================
RCS file: /sources/emacs/emacs/src/callint.c,v
retrieving revision 1.167
diff -u -r1.167 callint.c
--- src/callint.c	14 May 2008 07:49:11 -0000	1.167
+++ src/callint.c	17 Oct 2008 05:36:38 -0000
@@ -97,6 +97,7 @@
      This skips events that are integers or symbols.
 f -- Existing file name.
 F -- Possibly nonexistent file name.
+g -- Possibly nonexistent group name.
 G -- Possibly nonexistent file name, defaulting to just directory name.
 i -- Ignored, i.e. always nil.  Does not do I/O.
 k -- Key sequence (downcase the last event if needed to get a definition).
@@ -110,6 +111,7 @@
 r -- Region: point and mark as 2 numeric args, smallest first.  Does no I/O.
 s -- Any string.  Does not inherit the current input method.
 S -- Any symbol.
+u -- Possibly nonexistent user name.
 U -- Mouse up event discarded by a previous k or K argument.
 v -- Variable name: symbol that is user-variable-p.
 x -- Lisp expression read but not evaluated.
@@ -580,6 +582,11 @@
 				     Qnil, Qnil, Qnil, Qnil, Qnil);
 	  break;
 
+	case 'g':               /* Group name. */
+	  args[i] = Fcompleting_read (callint_message, make_groups_list (),
+				      Qnil, Qnil, Qnil, Qnil, Qnil, Qnil);
+	  break;
+
 	case 'G':		/* Possibly nonexistent file name,
 				   default to directory alone. */
 	  args[i] = Fread_file_name (callint_message,
@@ -754,6 +761,11 @@
 	  args[i] = Fintern (teml, Qnil);
 	  break;
 
+	case 'u':               /* User name. */
+	  args[i] = Fcompleting_read (callint_message, make_users_list (),
+				      Qnil, Qnil, Qnil, Qnil, Qnil, Qnil);
+	  break;
+
 	case 'v':		/* Variable name: symbol that is
 				   user-variable-p. */
 	  args[i] = Fread_variable (callint_message, Qnil);
Index: src/lisp.h
===================================================================
RCS file: /sources/emacs/emacs/src/lisp.h,v
retrieving revision 1.645
diff -u -r1.645 lisp.h
--- src/lisp.h	6 Oct 2008 16:17:24 -0000	1.645
+++ src/lisp.h	17 Oct 2008 05:36:38 -0000
@@ -3231,6 +3231,8 @@
 struct terminal;
 
 /* defined in sysdep.c */
+extern Lisp_Object make_users_list P_ ((void));
+extern Lisp_Object make_groups_list P_ ((void));
 #ifndef HAVE_GET_CURRENT_DIR_NAME
 extern char *get_current_dir_name P_ ((void));
 #endif
Index: src/sysdep.c
===================================================================
RCS file: /sources/emacs/emacs/src/sysdep.c,v
retrieving revision 1.318
diff -u -r1.318 sysdep.c
--- src/sysdep.c	7 Oct 2008 08:06:10 -0000	1.318
+++ src/sysdep.c	17 Oct 2008 05:36:38 -0000
@@ -108,6 +108,14 @@
 #include <memory.h>
 #endif /* USG */
 
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
+
+#ifdef HAVE_GRP_H
+#include <grp.h>
+#endif
+
 extern int quit_char;
 
 #include "keyboard.h"
@@ -181,6 +189,35 @@
 
 SIGMASKTYPE sigprocmask_set;
 
+Lisp_Object
+make_users_list () 
+{
+  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;
+}
+
+Lisp_Object
+make_groups_list () 
+{
+  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;
+}
 
 #if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME)
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-10-17  6:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-17  6:59 [PATCH] user/group name completion Antipov Dmitry

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).