Results 1 to 6 of 6

Thread: .emacs config: PATH and definitions

  1. #1
    Join Date
    Mar 2007
    Location
    Alaska
    Beans
    185
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    .emacs config: PATH and definitions

    I've been having trouble with this for a while, and had another thread open, but it's shifted to a different arena so I thought I'd open a new one with a more precise title.

    I'm trying to configure my .emacs file to allow:

    1. Correct PATH routing and detection by Emacs

    2. Allow Emacs to detect the definition of: ADMB_HOME=~/admb

    Now, the general method I've seen from a number of sources to set the PATH is to run some form of:

    Modify the .gnomerc file to read

    Code:
    #!/bin/bash
    source ~/.bashrc
    and then in the .bashrc file write

    Code:
    PATH=$PATH:~/admb/bin
    export PATH
    export ADMB_HOME=~/admb
    which will set both the proper PATH as well as allow for the definition of ADMB_HOME = ~/admb.

    For whatever reason, however, this has not functioned correctly. Nor has any variant of routing from a .profile, .xsession or bash_profile file with the PATH commands written in the bash_env or similar file, nor has simply entering

    Code:
    PATH=$PATH:~/admb/bin
    export PATH
    export ADMB_HOME=~/admb
    into the .gnomerc file, which has worked for some folks.

    Obviously, I'm making a basic error somewhere in terms of referencing the proper PATH commands. I've checked file permissions and everything else I can think of.

    What HAS worked for routing the PATH is to modify the .emacs file directly using

    Code:
    (normal-top-level-add-subdirs-to-load-path)
    (setq path-as-list (split-string (getenv "PATH") ":"))
    (add-to-list 'path-as-list "/home/arctos/admb/bin")
    (setenv "PATH" (mapconcat 'identity path-as-list ":"))
    which allows Emacs to add /home/arctos/admb/bin to the PATH.

    But I still need to tell Emacs that ADMB_HOME = ~/admb. Without that shift, Emacs can't run some of the admb commands or access header files needed to run the admb code.

    SO:

    can anyone perhaps see a reason why I am unable to use the first methods to properly route the PATH and the equivalency in Emacs

    or

    can anyone suggest how I can write the equivalency in the .emacs file directly so that Emacs knows ADMB_HOME=~/admb?

    Is it possible that any of this is somehow connected to the DASH shell instead of the BASH?

    Thanks!!
    Last edited by kvk; June 24th, 2009 at 07:57 PM.

  2. #2
    Join Date
    Jan 2009
    Beans
    Hidden!

    Re: .emacs config: PATH and definitions

    The .gnomerc file is sourced in a /bin/sh (i.e. dash) context if you are using GDM as your graphical login manager and gnome as your desktop. The .xprofile file is sourced (also in a dash context) if you are using GDM as your login manager, regardless of the desktop you use. The .xsessionrc file is sourced (once again, the context is dash) no matter which graphical login manager you use. I recommend using .xsessionrc instead of .gnomerc for this kind of thing.

    Since it's a dash context, you can't use 'source' to source ~/.bashrc, instead, you must simply use '.' (as in '. ~/.bashrc'). Also, if there's anything else in your ~/.bashrc that is bash specific, then sourcing ~/.bashrc won't work, no matter how you do it.

  3. #3
    Join Date
    Mar 2007
    Location
    Alaska
    Beans
    185
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: .emacs config: PATH and definitions

    Most excellent!! Thank you- I knew that the dash shell existed but didn't know much about it or how it interacted with bash and general system dynamics. That may have solved everything- I'm not quite sure; there are a number of tests I need to run.

    But just to make sure I have this correct:

    I wrote a .xsessionrc file in my home directory that contains only:

    Code:
    #!/bin/sh
    .~/.bashrc
    Then in the .bashrc file that already existed (created by the system) I added the lines

    Code:
    PATH=$PATH:~/admb/bin
    export PATH
    export ADMB_HOME=~/admb
    When I did so, and opened an Emacs window and ran

    Code:
    getenv
    PATH
    it listed '/home/arctos/admb/bin' correctly.

    It would not, however, load the admb directory, returning instead

    "Cannot open load file 'admb' "

    even though the .emacs file contained the line

    Code:
    (add-to-list 'load-path "~/admb")
    It wasn't until I added the lines

    Code:
    (normal-top-level-add-subdirs-to-load-path)
    (setq path-as-list (split-string (getenv "PATH") ":"))
    (add-to-list 'path-as-list "/home/arctos/admb/bin")
    (setenv "PATH" (mapconcat 'identity path-as-list ":"))
    back into the .emacs file that it was able to reference the admb directory and run commands and scripts contained in it, EVEN THOUGH I had removed the (add-to-list 'load-path "~/admb") line.

    My questions:

    1. If the .xsessionrc file references the .bashrc file correctly (and it appears that it does), why do I need the extra lines above to access the admb directory? Why won't the simple add-to-list load-path statement suffice?

    2. If I understand it correctly, the PATH has already been set via the .xsessionrc and .bashrc files, which is exactly what the above four lines do. THose same lines, however, don't instruct Emacs to open the admb directory, or do they? All of this appears redundant, but without those four lines, Emacs won't load the admb directory.

    THanks again- this has been a major hurdle! If I can just figure out why Emacs is demanding things be set as they are, I think I'll be home free. Thanks!!

  4. #4
    Join Date
    Jan 2009
    Beans
    Hidden!

    Re: .emacs config: PATH and definitions

    I don't actually use the load-path functionality in emacs, so I can't say from experience what the issue is here. However, both the emacs FAQ and the emacs wiki use a different method to change load-path.

    Code:
    (setq load-path (cons "~/admb/" load-path))
    Also, the wiki page says the '(normal-top-level-add-subdirs-to-load-path)' adds all subdirs of the current working directory to loadpath. It suggests using this to handle the load and get you back to your previous working directory:
    Code:
    (if (fboundp 'normal-top-level-add-subdirs-to-load-path)
        (let* ((my-lisp-dir "~/elisp/")
              (default-directory my-lisp-dir))
           (setq load-path (cons my-lisp-dir load-path))
           (normal-top-level-add-subdirs-to-load-path)))
    And finally, you can use 'Ctrl+h v' to check the value of load-path at any particular point in time. I don't see any suggestion in the documentation that changes to PATH are supposed to impact load-path.

  5. #5
    Join Date
    Apr 2007
    Beans
    3

    Re: .emacs config: PATH and definitions

    I was having trouble getting export to work too.

    I got around that by putting the environment variables I wanted in /etc/environment

  6. #6
    Join Date
    Mar 2007
    Location
    Alaska
    Beans
    185
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: .emacs config: PATH and definitions - SOLVED

    That works too, but I wanted to keep everything within my local user profile.

    Thanks again, Brandon!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •