🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #87303

[Not a bug]: env.el/setenv improvement.

#87303
From: Jan-Hein
Date: Fri, 30 Sep 1994 14:19
103 lines
4742 bytes
In GNU Emacs 19.27.1 (sparc-sun-sunos4.1.3, X toolkit) of Wed Sep 28 1994 on hzsbc03

This is not a bug report, but a proposed enhancement.

I sometimes need to change an environment variable from within emacs
(e.g. the envvar `PATH', to switch from one version of some package to
another version (installed in some other directory), in combination with
compile).  So what I really want is *editing* an environment value, not
*setting* it.

The following patch provides two features to the function `setenv':

- Environment variable name completion & history.  The completion must
match when deleting a variable name.

- Initial input (i.e. the current value) while reading a new value for
an environment variable.

These are all changes for interactive use.  The lisp interface stays the
same.

Regards,

-- Jan-Hein Buhrman -- AT&T Huizen NL ---  <J.H.Buhrman@ns-nl.att.com>  ---
---------------------- +31 35 87.4799 --- ...!att!hvgtw!hzsbg01!jbuhrma ---

diff -c emacs-19.27/lisp/ChangeLog.orig emacs-19.27/lisp/ChangeLog
*** emacs-19.27/lisp/ChangeLog.orig	Wed Sep 14 10:31:15 1994
--- emacs-19.27/lisp/ChangeLog	Fri Sep 30 14:51:22 1994
***************
*** 1,3 ****
--- 1,12 ----
+ Fri Sep 30 14:19:54 1994  Jan-Hein Buhrman  <J.H.Buhrman@ns-nl.att.com>
+ 
+ 	* env.el: (setenv): The prompt for environment variable name now
+ 	provides completion and history.
+ 	(setenv): The input buffer while prompting for the environment
+ 	variable value now initially contains the current value.
+ 	(var-name-history): New variable.
+ 	(read-envvar-name, envvar-list-list): New functions.
+ 
  Sun Sep 11 14:56:01 1994  Richard Stallman  <rms@mole.gnu.ai.mit.edu>
  
  	* Version 19.27 released.
diff -c emacs-19.27/lisp/env.el.orig emacs-19.27/lisp/env.el
*** emacs-19.27/lisp/env.el.orig	Wed Jun 22 06:40:08 1994
--- emacs-19.27/lisp/env.el	Fri Sep 30 14:19:13 1994
***************
*** 30,35 ****
--- 30,60 ----
  
  ;;; Code:
  
+ (defun envvar-list-list () "\
+ Return a list containing lists containing an environment variable name.
+ The return value is an alist whose elements' cars are envvar names
+ \(but without their corresponding values).
+ The envvar names are derived from the variable `process-environment'."
+   (mapcar (function
+ 	   (lambda (enventry)
+ 	     (list (substring enventry 0 (string-match "=" enventry)))))
+ 	  process-environment))
+ 
+ (defvar envvar-name-history nil
+   "History list for environment variable names.")
+ 
+ (defun read-envvar-name (prompt &optional mustmatch)
+   "Read environment variable name, prompting with PROMPT.
+ Optional second arg MUSTMATCH non-nil means require existing envvar name.
+ The variable `process-environment' is used for this."
+   (completing-read prompt
+ 		   (envvar-list-list)
+ 		   nil
+ 		   mustmatch
+ 		   nil
+ 		   'envvar-name-history))
+ 
+ 
  ;;;###autoload
  (defun setenv (variable &optional value unset)
    "Set the value of the environment variable named VARIABLE to VALUE.
***************
*** 40,48 ****
  This function works by modifying `process-environment'."
    (interactive
     (if current-prefix-arg
!        (list (read-string "Clear environment variable: ") nil t)
!      (let ((var (read-string "Set environment variable: ")))
!        (list var (read-string (format "Set %s to value: " var))))))
    (if unset (setq value nil))
    (if (string-match "=" variable)
        (error "Environment variable name `%s' contains `='" variable)
--- 65,74 ----
  This function works by modifying `process-environment'."
    (interactive
     (if current-prefix-arg
!        (list (read-envvar-name "Clear environment variable: " t) nil t)
!      (let ((var (read-envvar-name "Set environment variable: " nil)))
!        (list var (read-string (format "Set %s to value: " var)
! 			      (getenv var))))))
    (if unset (setq value nil))
    (if (string-match "=" variable)
        (error "Environment variable name `%s' contains `='" variable)
Technical Details
Message-ID: <9409301409.AA07743@hzsbg01>
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!howland.reston.ans.net!swiss.ans.net!solaris.cc.vt.edu!MathWorks.Com!news.cic.net!magnus.acs.ohio-state.edu!cis.ohio-state.edu!ns-nl.ATt.COM!J.H.Buhrman

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,3ec2f96107d65880,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1994-09-30 11:46:58 PST
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!howland.reston.ans.net!swiss.ans.net!solaris.cc.vt.edu!MathWorks.Com!news.cic.net!magnus.acs.ohio-state.edu!cis.ohio-state.edu!ns-nl.ATt.COM!J.H.Buhrman
From: J.H.Buhrman@ns-nl.ATt.COM (Jan-Hein)
Newsgroups: gnu.emacs.bug
Subject: [Not a bug]: env.el/setenv improvement.
Date: 30 Sep 1994 10:19:35 -0400
Organization: GNUs Not Usenet
Lines: 103
Sender: daemon@cis.ohio-state.edu
Approved: bug-gnu-emacs@prep.ai.mit.edu
Distribution: gnu
Message-ID: <9409301409.AA07743@hzsbg01>