Setting the working directory of IPython Shell to that of the python file being executed in Canopy - editor

I am new to IPython and I am using the Canopy distribution. The default value of the shell's working directory is /home/username. This is a bit painful, when I work on files which need other files present in the corresponding folder that I am working in.
So, I always manually change it to folder in which the file (which I am trying to execute) is present.
I found this relevant question, but my question is slightly different. Also, I couldn't understand the answer provided there really well.
Is there a shorter way of setting up the working directory of the IPython shell to that of the file on which I am working? Like a command?
Thanks for your help

You can use cd inside of iPython. cd stands for change directory
> cd /home/username/my_otherdirectory

This is a feature that is on our list of features, but quite low on priority. Canopy provides a right click context menu option to switch to the currently active editor's directory (see this).
Also, as a temporary work-around, you could use the following macro to get your job done.
# -*- coding: utf-8 -*-
def run():
code_task = get_active_task()
from os.path import dirname
def change_directory():
code_editor = code_task.active_editor
if not code_editor:
return
python_pane = code_task.python_pane
active_dir = dirname(code_editor.obj.path)
python_pane.execute_command(u'cd %s\n' % active_dir)
code_task.on_trait_change(change_directory, 'active_editor')
Note: You'll have to run this macro, each time you have closed and reopened the editor window.
See 1 and 2 for instructions on how to create a macro and for more information about macros in Canopy.

Right click on python tab in Canopy and from menu select 'Keep Directory Synced to Editor'. It will set directory containing your source file as your current working directory.You can set any directory as your working directory by selecting 'Change Working Directory' from right click menu

Related

Multiline command-line editing in Gforth console

I have just started learning the Forth programming language.
I'm using Gforth on Ubuntu. In Gforth interactive console, I want to do indentation but it requires changing line. Enter key didn't work, it executed code. For comparison, for example, when one tests JavaScript code in web browser console, shift+enter change line without executing code. I want something like that. What key should I press? Is there a way other than using text editors like vim?
Best.
Gforth doesn't support multiline editing (see the manual).
A workaround is to edit a file in your favorite editor in another window and reload this file in Gforth console as:
include /tmp/scratch.fs
An external file can be also edited in Gforth console via a command like:
"vim /tmp/scratch.fs" system
So a one-liner for that is:
"vim /tmp/scratch.fs" system "/tmp/scratch.fs" included
That can be wrapped into a definition as:
: scratch "vim /tmp/scratch.fs" system "/tmp/scratch.fs" included ;
So the word scratch will open an editor and than load the edited file.
NB: if you use a quite old build of Gforth, you have to use s" ccc" instead of "ccc" for string literals.
To conditionally include/exclude some parts in a file the words [defined] and [if] can be used; to erase the previous instance of the loaded definitions the word marker can be used as:
[defined] _clear [if] _clear [then]
marker _clear
\ some definitions
\ ...
Take into account that usual control-flow words can be used in definitions only.

What is the different between PATH=:$PATH and PATH="$PATH:" and other export lines

I have a question about following lines related to adding PATH to enviroment.
export PATH=/usr/loca/cuda/bin:$PATH
export PATH=/usr/local/cuda-9.1/bin${PATH:+:${PATH}}
export PATH="/home/ics_vr/anaconda3/bin:$PATH"
export PATH="$PATH:/home/user/anaconda3/bin"
Regardless the content of path in each export lines, my first question is how do I distinguish thoes lines starting with export PATH=? e.g. grammer and its functions, regardless the variable I used in thoes lines.
Secondly, I see many people use # to comment on/off to switch those path,but this is not convenient. Is there any union way to realize all, without commenting the export line every time?
This is convenient because people want to use system python for example as default, but if the path is settled not properly, anaconda python interpreter will be settled by default. We need a way that default is the system python interpreter, and when I need anaconda, I will use
source activate ENV_I_BUILD
Thank you for your time and help. I am very appreciate on that.
The environment variable PATH is a list of colon separated folder paths where to find executables.
The order in which folder paths are places in this variable is very important. Indeed, if you call a program from the command line, the executable will first be searched in the first folder path, then if it's not there the second and so on...
Anaconda ships with a python installation (either 2.x or 3.x).
If you export:
export PATH="/home/ics_vr/anaconda3/bin:$PATH"
then the python in "/home/ics_vr/anaconda3/bin/anaconda3" will be used preferentially. Thus, if you want to keep the system python by default, you might want to use:
export PATH="$PATH:/path/to/whatever/conda"
The source activate ... will prepend the environment bin folder in your PATH anyway. So if you activate an environment, the system python will be superseeded by the python of the conda env.
As for the two lines:
export PATH=/usr/loca/cuda/bin:$PATH
export PATH=/usr/local/cuda-9.1/bin${PATH:+:${PATH}}
you will have to decide what executables you want first in your PATH variable.
For information, you can set multiple folders in your PATH in one line:
export PATH="$PATH:/usr/loca/cuda/bin:/home/ics_vr/anaconda3/bin:/my/personal/bin"
Do not forget to add what was already in your PATH variable when exporting a new PATH if you do not want to loose basic commands listed in, for example, "/usr/bin" or "/usr/local/bin".

Windows 7 - Add Path

I need to add a new path (sumatraPDF) on my PATH variable.
I don't know why it does not work...
I think everything is right but when I try to execute sumatrapdf.exe from CMD it cannot find the program.
This is what I did:
The path is correct, I checked it 1000 times.
The idea is use LaTeX with sublimetext and when I save a .text file sumatra has to open and show to me the result. If I want that I have to add the path of SumatraPDF... but it does not work.
I think you are editing something in the windows registry but that has no effect on the path.
Try this:
How to Add, Remove or Edit Environment variables in Windows 7
the variable of interest is the PATH
also you can type on the command line:
Set PATH=%PATH%;(your new path);
Another method that worked for me on Windows 7 that did not require administrative privileges:
Click on the Start menu, search for "environment," click "Edit environment variables for your account."
In the window that opens, select "PATH" under "User variables for username" and click the "Edit..." button. Add your new path to the end of the existing Path, separated by a semi-colon (%PATH%;C:\Python27;...;C:\NewPath). Click OK on all the windows, open a new CMD window, and test the new variable.
I founded the problem:
Just insert the folder without the executable file.
so Instead of:
C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe
you have to write this:
C:\Program Files (x86)\SumatraPDF\
In answer to the OP:
The PATH environment variable specifies which folders Windows will search in, in order to find such files as executable programs or DLLs. To make your Windows installation find your program, you specify the folder that the program resides in, NOT the program file itself!
So, if you want Windows to look for executables (or other desired files) in the folder:
C:\PHP
because, for example, you want to install PHP manually, and choose that folder into which to install PHP, then you add the entry:
C:\PHP
to your PATH environment variable, NOT an entry such as "C:\PHP\php.exe".
Once you've added the folder entry to your PATH environment variable, Windows will search that folder, and will execute ANY named executable file you specify, if that file happens to reside in that folder, just the same as with all the other existing PATH entries.
Before editing your PATH variable, though, protect yourself against foul ups in advance. Copy the existing value of the PATH variable to a Notepad file, and save it as a backup. If you make a mistake editing PATH, you can simply revert to the previous version with ease if you take this step.
Once you've done that, append your desired path entries to the text (again, I suggest you do this in Notepad so you can see what you're doing - the Windows 7 text box is a pain to read if you have even slight vision impairment), then paste that text into the Windows text box, and click OK.
Your PATH environment variable is a text string, consisting of a list of folder paths, each entry separated by semicolons. An example has already been given by someone else above, such as:
C:\Program Files; C:\Winnt; C:\Winnt\System32
Your exact version may vary depending upon your system.
So, to add "C:\PHP" to the above, you change it to read as follows:
C:\Program Files; C:\Winnt; C:\Winnt\System32; C:\PHP
Then you copy & paste that text into the windows dialogue box, click OK, and you should now have a new PATH variable, ready to roll. If your changes don't take effect immediately, you can always restart the computer.
The path is a list of directories where the command prompt will look for executable files, if it can't find it in the current directory. The OP seems to be trying to add the actual executable, when it just needs to specify the path where the executable is.
Try this in cmd:
cd address_of_sumatrapdf.exe_file && sumatrapdf.exe
Where you should put the address of your .exe file instead of adress_of_sumatrapdf.exe_file.

VIM folding for ERB files?

Vim noob here. I have code folding working in most places, via indent mode, but for some reason I cannot get Vim to fold .html.erb files in ruby... even with indents.
Here's the relevant region of my vimrc. Is there something else I need to do to make Vim aware of the erb files? Is it possible to customize my folding per file type?
I'm running all the Janus plugins, so have rails.vim, etc. all installed.
let ruby_fold=1
set foldmethod=indent
set foldcolumn=0
set foldlevel=99
nnoremap <space> za<cr>
It's a difficult question, because there's probably something in your vim configuration that inhibits folding and I, for example, can't reproduce it. But I can suggest a few things you could try.
First of all, check what the values of those settings are in the actual buffer. Meaning, open up an erb file and check if the settings are correct. In order to do that, you can type, for example, set foldmethod, which will echo the current value of foldmethod to the screen. If one of the settings doesn't match the ones in your .vimrc, then that might be the problem.
Also, see if the file really does have the "eruby" filetype. If it's not displayed in your statusline, you could check that with set filetype.
Most importantly, one way of customizing settings per filetype is by creating a file with the filetype's name inside the ~/.vim/ftplugin directory. In your case, you can create the file ~/.vim/ftplugin/eruby.vim and put any filetype-specific settings in it. Setting them with setlocal instead of set will keep them local to the file. If it turns out the settings for erb are off, you can "fix" them by putting the values you want there.

How can I force the SConscript builder to change directory?

currently I'm trying to port a million-sloc legacy project from dull .cmd scripts to SCons. Parts of it are VC++, others are Delphi. Creating SConscripts for the C++ pieces was a breeze.
To build the delphi part I've written a very simple builder which detects whether it is a program or library project. Calling the builder after chaining via SConscript makes scons to call dcc32 $subdir/project.dpr what misleads dcc32 to look for units in the current directory instead of the $subdir.
Is there a way to tell scons to enter the $subdir before executing commands residing in the sconscript or should I fix it within the builder?
Thank you in advance
SCons already changes to the directory of sub-directory SConscripts when reading them, so it looks like the problem is going to have to be fixed in the actual builder.
Once the scripts are parsed, and SCons is running the build commands, it stays in the top-level directory. Commands are then issued using path names relative to that top-level directory. The way to change this behavior is to use the chdir keyword in your Builder.
The example from the scons man page is as follows:
b = Builder(action='build < ${SOURCE.file} > ${TARGET.file}',
chdir=1)
env = Environment(BUILDERS = {'MyBuild' : b})
env.MyBuild('sub/dir/foo.out', 'sub/dir/foo.in')
You need to specify the .file component as the use of chdir does not change the names passed to the builder, i.e. they are still relative to the top-level directory.

Resources