all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* sourcing environment
@ 2006-10-10 22:09 Tak Ota
  2006-10-11  8:35 ` Stephen Leake
  0 siblings, 1 reply; 6+ messages in thread
From: Tak Ota @ 2006-10-10 22:09 UTC (permalink / raw)


Hello,

I use emacs at work for embedded software development.  When switching
gears frequently between different cross compilation environment it is
common practice to set/change environment variables by sourcing shell
scripts.

Like many seasoned emacs users once I start emacs I don't want to
discontinue that process however to change environment I need to kill
the current emacs and source shell script to change environment and
restart emacs again.  To alleviate this annoying inconvenience I now
use the following custom function to tweak the environment on the fly.

(defun source (script &optional shell)
  "Source the specified shell script.
Source the shell SCRIPT and import the environment into this emacs.
The optional SHELL specifies the shell other than the default `shell-file-name'"
  (interactive "fscript file: ")
  (if (null shell)
      (setq shell shell-file-name))
  (with-temp-buffer
    (call-process shell nil t nil "-c" (concat "source " script "; printenv"))
    (while (re-search-backward "^\\([^=]+\\)=\\(.*\\)$" nil t)
      (setenv (match-string 1) (match-string 2)))))

Has there been something equivalent to this already built into some
existing scripts?  I bet many people have encountered this need.
Please educate my ignorance.

-Tak

P.S.

I don't subscribe to the mailing list so please reply explicitly.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sourcing environment
  2006-10-10 22:09 sourcing environment Tak Ota
@ 2006-10-11  8:35 ` Stephen Leake
  2006-10-11 16:07   ` Tak Ota
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Leake @ 2006-10-11  8:35 UTC (permalink / raw)
  Cc: emacs-devel

Tak Ota <Takaaki.Ota@am.sony.com> writes:

> ... When switching gears frequently between different cross
> compilation environment it is common practice to set/change
> environment variables by sourcing shell scripts.

I don't use shell scripts for this; I use Emacs functions:

(defun ghdl-0.25 ()
  "ghdl only; run from a DOS shell"
  (interactive)
  (setq exec-path
        (list
         (expand-file-name "~/bin")
         (getenv "INSTALL_BIN")
         "c:/Gnu/Emacs/emacs-21.3/bin"
         "c:/Gnu/Ghdl-0.25/bin"
         "c:/Windows/system32"))
  (setenv "PATH" (mapconcat 'identity  exec-path  path-separator))
  )
  
(defun sal-no-network ()
  "set LM_LICENSE_FILE to just the hardware key, to avoid network delays"
  (interactive)
  (setenv "LM_LICENSE_FILE" "foo")
  )

-- 
-- Stephe

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sourcing environment
  2006-10-11  8:35 ` Stephen Leake
@ 2006-10-11 16:07   ` Tak Ota
  2006-10-11 19:00     ` Giorgos Keramidas
  0 siblings, 1 reply; 6+ messages in thread
From: Tak Ota @ 2006-10-11 16:07 UTC (permalink / raw)
  Cc: emacs-devel

Thanks for the suggestion.  I understand what you do but in my case I
don't prepare the shell scripts but they come as a part of software
development kit from system silicon vendors.  I used to hand translate
those shell scripts into custom elisp functions like you show below
but that soon got too cumbersome to maintain for multiple platforms.
What I want to automate is the following process without loosing the
currently opened buffers.

M-x kill-emacs
$ source env-xxx.sh
$ emacs

-Tak

Wed, 11 Oct 2006 04:35:16 -0400: Stephen Leake <stephen_leake@member.fsf.org> wrote:

> Tak Ota <Takaaki.Ota@am.sony.com> writes:
> 
> > ... When switching gears frequently between different cross
> > compilation environment it is common practice to set/change
> > environment variables by sourcing shell scripts.
> 
> I don't use shell scripts for this; I use Emacs functions:
> 
> (defun ghdl-0.25 ()
>   "ghdl only; run from a DOS shell"
>   (interactive)
>   (setq exec-path
>         (list
>          (expand-file-name "~/bin")
>          (getenv "INSTALL_BIN")
>          "c:/Gnu/Emacs/emacs-21.3/bin"
>          "c:/Gnu/Ghdl-0.25/bin"
>          "c:/Windows/system32"))
>   (setenv "PATH" (mapconcat 'identity  exec-path  path-separator))
>   )
>   
> (defun sal-no-network ()
>   "set LM_LICENSE_FILE to just the hardware key, to avoid network delays"
>   (interactive)
>   (setenv "LM_LICENSE_FILE" "foo")
>   )
> 
> -- 
> -- Stephe
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sourcing environment
  2006-10-11 16:07   ` Tak Ota
@ 2006-10-11 19:00     ` Giorgos Keramidas
  2006-10-11 19:15       ` Tak Ota
  0 siblings, 1 reply; 6+ messages in thread
From: Giorgos Keramidas @ 2006-10-11 19:00 UTC (permalink / raw)
  Cc: stephen_leake, emacs-devel

On 2006-10-11 09:07, Tak Ota <Takaaki.Ota@am.sony.com> wrote:
> Thanks for the suggestion.  I understand what you do but in my case I
> don't prepare the shell scripts but they come as a part of software
> development kit from system silicon vendors.  I used to hand translate
> those shell scripts into custom elisp functions like you show below
> but that soon got too cumbersome to maintain for multiple platforms.
> What I want to automate is the following process without loosing the
> currently opened buffers.
> 
> M-x kill-emacs
> $ source env-xxx.sh
> $ emacs

It looks like you would have to spawn a subshell, save its environment
somewhere, source the script, save the new environment, diff the two
environments and 'translate' the diff output to appropriate

    (setenv "FOO" "bar")

or

    (setenv "FOO" nil)

calls :(

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sourcing environment
  2006-10-11 19:00     ` Giorgos Keramidas
@ 2006-10-11 19:15       ` Tak Ota
  2006-10-11 20:22         ` Giorgos Keramidas
  0 siblings, 1 reply; 6+ messages in thread
From: Tak Ota @ 2006-10-11 19:15 UTC (permalink / raw)
  Cc: stephen_leake, emacs-devel

Wed, 11 Oct 2006 22:00:12 +0300: Giorgos Keramidas <keramida@ceid.upatras.gr> wrote:

> > M-x kill-emacs
> > $ source env-xxx.sh
> > $ emacs
> 
> It looks like you would have to spawn a subshell, save its environment
> somewhere, source the script, save the new environment, diff the two
> environments and 'translate' the diff output to appropriate
> 
>     (setenv "FOO" "bar")
> 
> or
> 
>     (setenv "FOO" nil)
> 
> calls :(

That is pretty much what I do with the following function.  My
question is if this equivalent feature is already available in any
form in the current emacs?

-Tak

;;
;; Shell Script Sourcing
;;
(defun source (script &optional shell keep-current-directory)
  "Source the specified shell script.
Source the shell SCRIPT and import the environment into this
emacs.  The optional SHELL specifies the shell other than the
default `shell-file-name'.  When KEEP-CURRENT-DIRECTORY is nil,
which is the default, the current directory is temporarily
changed to the directory where the script resides while sourcing
the script."
  (interactive "fscript file: ")
  (if (null shell)
      (setq shell shell-file-name))
  (with-temp-buffer
    (unless keep-current-directory
      (setq default-directory (file-name-directory script)))
    (call-process shell nil t nil "-c" (concat "source " script "; printenv"))
    (while (re-search-backward "^\\([^=]+\\)=\\(.*\\)$" nil t)
      (setenv (match-string 1) (match-string 2)))))

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sourcing environment
  2006-10-11 19:15       ` Tak Ota
@ 2006-10-11 20:22         ` Giorgos Keramidas
  0 siblings, 0 replies; 6+ messages in thread
From: Giorgos Keramidas @ 2006-10-11 20:22 UTC (permalink / raw)
  Cc: stephen_leake, emacs-devel

On 2006-10-11 12:15, Tak Ota <Takaaki.Ota@am.sony.com> wrote:
> Wed, 11 Oct 2006 22:00:12 +0300: Giorgos Keramidas <keramida@ceid.upatras.gr> wrote:
> > > M-x kill-emacs
> > > $ source env-xxx.sh
> > > $ emacs
> > 
> > It looks like you would have to spawn a subshell, save its environment
> > somewhere, source the script, save the new environment, diff the two
> > environments and 'translate' the diff output to appropriate
> > 
> >     (setenv "FOO" "bar")
> > 
> > or
> > 
> >     (setenv "FOO" nil)
> > 
> > calls :(
> 
> That is pretty much what I do with the following function.  My
> question is if this equivalent feature is already available in any
> form in the current emacs?

I don't think so, but I don't know everything about Emacs :-/

> ;;
> ;; Shell Script Sourcing
> ;;
> (defun source (script &optional shell keep-current-directory)
>   "Source the specified shell script.
> Source the shell SCRIPT and import the environment into this
> emacs.  The optional SHELL specifies the shell other than the
> default `shell-file-name'.  When KEEP-CURRENT-DIRECTORY is nil,
> which is the default, the current directory is temporarily
> changed to the directory where the script resides while sourcing
> the script."
>   (interactive "fscript file: ")
>   (if (null shell)
>       (setq shell shell-file-name))
>   (with-temp-buffer
>     (unless keep-current-directory
>       (setq default-directory (file-name-directory script)))
>     (call-process shell nil t nil "-c" (concat "source " script "; printenv"))
>     (while (re-search-backward "^\\([^=]+\\)=\\(.*\\)$" nil t)
>       (setenv (match-string 1) (match-string 2)))))

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-10-11 20:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-10 22:09 sourcing environment Tak Ota
2006-10-11  8:35 ` Stephen Leake
2006-10-11 16:07   ` Tak Ota
2006-10-11 19:00     ` Giorgos Keramidas
2006-10-11 19:15       ` Tak Ota
2006-10-11 20:22         ` Giorgos Keramidas

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.