/usr/share/emacs/site-lisp/emacs-goodies-el/edit-env.el is in emacs-goodies-el 35.2ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | ;;; edit-env.el --- display and edit environment variables
;; Copyright (C) 2001 Benjamin Rutt
;;
;; Maintainer: Benjamin Rutt <brutt@bloomington.in.us>
;; Version: 1.0
;; This file is not part of GNU Emacs.
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 2, or (at your
;; option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, send e-mail to
;; this program's maintainer or write to the Free Software Foundation,
;; Inc., 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This file uses the widget library to display, edit, delete and add
;; environment variables. Inspired by "G c" in a gnus *Group* buffer.
;; Bug reports or patches are welcome, please use the above email
;; address.
;;; Usage:
;; put this file in your load-path and add the line
;;
;; (require 'edit-env)
;;
;; to your ~/.emacs file.
;;
;; Then, type
;;
;; M-x edit-env
;;
;; to enter the environment editor. To change variables, simply edit
;; their values in place. To delete variables, delete their values.
;; To add variables, add a new rows to the list at the bottom by
;; pressing [INS]; then, add a new name/value pair of the form
;; VAR=VALUE (e.g. FOO=BAR). After changing and/or deleting and/or
;; adding environment variables, press the [done] button at the top.
;; Note that environment variable changes will only be visible to your
;; current emacs session or child processes thereof.
;;; Code:
;; XEmacs compatibility stuff
(if (string-match "XEmacs" (emacs-version))
(require 'overlay))
(require 'widget)
(require 'wid-edit)
(eval-when-compile (require 'cl))
(defvar edit-env-ls nil)
(defvar edit-env-changed-ls nil)
(defvar edit-env-added-ls nil)
(defun edit-env-update ()
(let ((var nil)
(value nil)
(vars-changed nil))
(when edit-env-changed-ls
(mapcar
(lambda (x)
(setq var (car x))
(setq value (widget-value (cadr x)))
(if (equal value "")
(setenv var nil) ;; i.e. unset var
(setenv var value))
(add-to-list 'vars-changed var))
edit-env-changed-ls)
(setq edit-env-changed-ls nil))
(when edit-env-added-ls
(mapcar
(lambda (x)
(if (and x (not (string-match "^[ \t\n]*$" x)))
(progn
(let ((splits (split-string x "=")))
(if (not (= (length splits) 2))
(message "invalid format %s" x)
(setq var (car splits))
(setq value (cadr splits))
(if value (add-to-list 'vars-changed var))
(setenv var value))))))
(widget-value edit-env-added-ls))
(setq edit-env-added-ls nil))
(when vars-changed
;; Need to regenerate the buffer before burial. An alternative
;; to re-generation followed by burial would be simply to
;; kill-buffer.
(edit-env)
(message
(format "Updated environment variable%s %s"
(if (> (length vars-changed) 1) "s" "")
(mapconcat 'identity vars-changed ", "))))
(bury-buffer)))
(defun edit-env-mark-changed (widget)
(add-to-list 'edit-env-changed-ls
(list (widget-get widget 'environment-variable-name)
widget)))
;; Local copy from `copy-list' from cl.el (PSG, Closes #340735)
(defun edit-env-copy-list (list)
"Return a copy of a list, which may be a dotted list.
The elements of the list are not copied, just the list structure itself."
(if (consp list)
(let ((res nil))
(while (consp list) (push (pop list) res))
(prog1 (nreverse res) (setcdr res list)))
(car list)))
;;;###autoload
(defun edit-env ()
"Display, edit, delete and add environment variables."
(interactive)
(setq edit-env-ls nil
edit-env-changed-ls nil
edit-env-added-ls nil)
(switch-to-buffer "*Environment Variable Editor*")
(kill-all-local-variables)
(let ((inhibit-read-only t))
(erase-buffer))
(let ((all (overlay-lists)))
;; Delete all the overlays.
(mapcar 'delete-overlay (car all))
(mapcar 'delete-overlay (cdr all)))
(widget-insert "Edit environment variables below, and press ")
(let ((pair nil)
(var nil)
(val nil)
(longest-var 0)
(current-widget nil))
(setq edit-env-ls (edit-env-copy-list process-environment))
(setq edit-env-ls (sort edit-env-ls (lambda (a b) (string-lessp a b))))
(widget-create 'push-button
:notify (lambda (widget &rest ignore)
(edit-env-update))
:help-echo "press to update environment variables"
"done")
(widget-insert ".\n")
(mapcar
(lambda (x)
(let* ((pair (split-string x "="))
(var (car pair))
(val (cadr pair)))
(setq longest-var (max longest-var (length var)))))
edit-env-ls)
(mapcar
(lambda (x)
(let* ((pair (split-string x "="))
(var (car pair))
(val (or (cadr pair) "")))
(widget-insert "\n")
(widget-insert (format (format "%%%ds" (1+ longest-var)) var))
(widget-insert " ")
(setq current-widget
(widget-create 'editable-field
:size (1- (length val))
:notify (lambda (widget &rest ignore)
(edit-env-mark-changed widget))
:format "%v" val))
(widget-put current-widget 'environment-variable-name var)))
edit-env-ls)
(widget-insert "\n\nTo add environment variables, ")
(widget-insert "add rows of the form VAR=VALUE\n")
(widget-insert "to the following list:\n")
(setq edit-env-added-ls
(widget-create
'editable-list
:entry-format "%i %d %v"
:value nil
'(editable-field :value "")))
(use-local-map widget-keymap)
(widget-setup)
(setq truncate-lines t)
;; in future GNU emacs >= 21, auto-show-mode may be removed.
(when (fboundp 'auto-show-mode)
(auto-show-mode 1))
(goto-char (point-min))))
(provide 'edit-env)
;;; edit-env.el ends here
|