I want to keep my Vim and Emacs configurations under version control, but I don't want my entire home folder there (or rather, I do, but there should be 3 separate repositories). With Emacs it's easy; if ~/.emacs doesn't exist, then ~/.emacs.d/init.el is used as the init file. So I can have a separate Git repo in ~/.emacs.d/. With Vim, it seems .vimrc can only exist in home folder and not in ~/vimfiles (the equivalent to ~/.emacs.d). Is this the best way to put .vimrc under version control?
Just put a dummy .vimrc in ~ with just a single line:
source ~/path/to/real/vimrc
Works like a charm
Perhaps moving your .vimrc to ~/.vim/ and symlinking to home will do?
Other, much more modular approach is to move your startup script to ~/.vim/plugins/, perhaps create a subdirectory there, and single or multiple init scripts: Vim will do a :runtime! plugin/**/*.vim when starting.
As #Progo suggests in their answer, ~/.vimrc settings can be moved into a "plugin" script within a file like ~/.vim/plugin/00rc.vim.
There are a couple of things to keep in mind when going down this road:
Users and plugins alike expect that the settings in ~/.vimrc have been loaded before plugins are as described in :help startup. ~/.vim is usually first in 'runtimepath', but if the user has other plugins in ~/.vim/plugin, the .vimrc replacement must be lexicographically first to ensure it is loaded first, perhaps ~/.vim/plugin/00rc.vim.
When the vim startup process moves from step 3 'Execute Ex commands' (where .vimrc would have been read; again, see :help startup) to step 4 'Load the plugin scripts', it runs :runtime! plugin/**/*.vim. This command looks through 'runtimepath' for matching files to source and then starts sourcing them. This means that if something in ~/.vim/plugin/00rc.vim modifies 'runtimepath' then it will have been too late to affect which plugins are run. This occurs most commonly with pathogen and in that case it can be worked around by adding the following lines to the end of ~/.vim/plugin/00rc.vim:
" Since this "vimrc" is really run as a plugin, vim has already compiled the
" list of paths/plugins that it wil execute at startup.
" As a result, the pathogen plugins must be run manually.
runtime! bundle/*/plugin/**/*.vim
runtime! bundle/*/after/plugin/**/*.vim
Finally, (again as explained in :help startup), if a ~/.vimrc file isn't present, vim will search for other files like ~/.exrc so it may be necessary to remove them if their contents are unwanted.
Adds a step to the process, but I just have a bash script deploy.sh in my vim settings.
#!/bin/bash
if [ -f ~/.vimrc ] && [ ! -L ~/.vimrc ]
then
echo "Backing up existing ~/.vimrc to ~/.vimrc.bak"
mv ~/.vimrc ~/.vimrc.bak
fi
if [ -L ~/.vimrc ]
then
echo "Already have ~/.vimrc symlink, we're good"
else
echo "Creating symlink ~/.vimrc, which points to ~/.vim/vimrc"
ln -s ~/.vim/vimrc ~/.vimrc
fi
git submodule init
git submodule update
You could just keep a backup in version control and deploy it (i.e. move it) to your home directory when you need it. You could write an easy script to manage all this handling so at least transparently it won't seem like a lot of annoying work to move it back and forth.
Related
So I've finally decided to learn Lisp. I'm reading Practical Common Lisp and I'm using Lispbox (not the one the book recommends - it's no longer available, but it seems this is suitable nonetheless).
So far in my career I have managed to avoid wresting with emacs, but I guess that part of my life is over :-) Actually, I'm kind of excited - this is a brand new world.
When saving .lisp files, the out-of-the-box setup dumps these files into the lispbox-0.7 folder (which is also the LISPBOX_HOME env.var). My math teacher taught me, "If you don't know what you're doing, at least do it neatly." So I want to at least keep my work in a nice tidy folder. I can specify the full path on saving/loading. But can I tell (lispbox|emacs|whatever) to use a different folder by default?
If it matters: I will likely use the Windows version more often, but I also have a setup on Ubuntu.
I have looked at this and this and this. I tried adding these to the .emacs file (one at a time):
(setq default-directory "C:/Work/lisp/")
(cd "C:/Work/lisp/")
To open the .emacs file I used C-x C-f~/.emacs
If I try changing the LispBox shortcut's "Start in" property, it fails to load at all.
M-xcd c:/work/lisp does work, but I have to do it every time I launch LispBox
What I'm doing in the meantime: I've created a separate lisp folder beside the lispbox-0.7 folder. That way I can prepend ../lisp/ before any filename. This isn't so bad, especially with the tab auto-complete.
Found it!
The reason modifying .emacs wasn't working is because of the lispbox.bat file. It has this line:
%EMACS% --no-init-file --no-site-file --eval=%TO_EVAL%
So took out the two "no" parameters, leaving this...
%EMACS% --eval=%TO_EVAL%
...and it worked.
This worried me, though. Why would the default not want to load the .emacs file? I guess once I understand all of this better I'll have an answer. Until then, I restored the above, the changed this line...
set TO_EVAL="(progn (load \"lispbox\") (slime))"
...to this...
set TO_EVAL="(progn (load \"lispbox\") (slime) (cd \"C:/work/lisp/\"))"
Now I'm happy.
I know nothing about Lisp Box, and not all of what you describe is clear to me. But here goes.
It sounds like you are looking for a way to make c:/work/lisp the default directory when you start Emacs. For that, using an MS Windows shortcut, putting that folder in the Start in field does indeed accomplish that. But you speak of a LispBox shortcut's Start in. If by that you just mean an Emacs shortcut, then it should work.
But of course you need to use Windows syntax for the folder - not c:/work/lisp, but c:\work\lisp.
Is that what the problem was?
The Windows shortcut is a Windows thing. Emacs is different: it accepts / as a folder separator.
Tip: If that solves your problem, you might also want to start Emacs in Dired mode on that same folder, that is, if that folder is the one you will use a lot. To do that, add that folder at the end of the command line - again, using Windows syntax, but between double-quotes:
c:\your\path\to\runemacs.exe "c:\work\lisp"
Try starting lispbox.bat from the directory you want to save files to. For example, from the OS command prompt:
cd c:\work\lisp
path-to-bat-file\lispbox.bat
You can also cd to c:\work\lisp in listbox.bat before it executes Emacs. For Linux it looks like this in lispbox.sh:
#!/bin/bash
if [ "${0:0:2}" = "./" ]; then
export LISPBOX_HOME=`pwd`/../../..
else
export LISPBOX_HOME=`dirname $0`/../../..
fi
cd ~/work/lisp
export SBCL_HOME=${LISPBOX_HOME}/sbcl-1.0.42/lib/sbcl
exec ${LISPBOX_HOME}/Emacs.app/Contents/MacOS/Emacs --no-init-file --no-site-file --eval='(progn (load "lispbox") (slime))'
For some reason, when I type in commands I'm used to on linux, it works perfectly, as it does in bash... But in eshell, it doesn't work.
I've narrowed the problem to a trivial and small sample, as follows:
$ du
c:/Program: command not found
$ which bash
c:/Program Files (x86)/Git/bin/bash.exe
How do I get this working? (du is whatever it is by default... It's implemented in elisp, I haven't made any unusual changes there, that is, it's a compiled lisp function in `em-unix.el')
I would've expected something along the lines of "You have used 1.3 GiB of disk space", rather than that command not found error.
It doesn't use bash.exe, but it can use du.exe, when present.
On my system:
c: gutov $ which bash.exe
which: no bash.exe in ...
c: gutov $ which du.exe
h:/Apps/System/gnuwin32/bin/du.exe
From your error message I can tell that it calls some command and fails because it doesn't properly quote the path to executable (which contains spaces). Maybe you should do M-x report-emacs-bug.
Overall, I recommend:
1) Uninstall Git and reinstall it selecting the second option when asked about your PATH environment ("Run Git from the Windows Command Prompt"). This will remove the unix tools packaged with it from PATH.
2) Install in some directory without spaces and add to PATH unix tools from GnuWin32 project, or from Eli Zaretski's ports. The latter contains fewer packages overall, but it has a much faster find, for example. You can mix them.
Alternatively, maybe you can get away with just reinstalling Git into directory without spaces.
I am using Emacs 23 and have the following problem:
I run our project's build system from within Emacs like M-x compile -> cd /foo/bar && ./build
The build system now does some magic, "cd"s into some subdirectory for the build process and then gcc throws an error:
../src/somesource.cc:50 error: blablabla
Now the problem is that Emacs won't find that path, because it assumes the compile process started out in /foo/bar, and not in /foo/bar/builddir. So the leading "../" is not working for Emacs, e.g. when running compile-goto-error. Is there a way to tell Emacs to try skipping leading "../"?
The best solution might be to change the build system to emit messages when it changes directories. Emacs looks for
Entering directory `...'
...
Leaving directory `...'
(See the compilation-directory-matcher variable. If your build system does emit messages when it changes directories, but they're not in the format Emacs is looking for, you can add new regexps to compilation-directory-matcher.)
The other solution is to change compilation-search-path (which is a list of directories).
On a few occasions I solved by passing output of the make through sed.
First, debugged it interactively 'Compile command: make | sed 's/x/y/' . And then repackaged it as a custom emacs interactive function.
I have a question about clearcase. in linux, I open a terminal, and use "xclearcase" command to lunch file browser of clearcase. Then I check out a file and I want to open it in Emacs, I know I should cd to the folder contains the checked out file, but before I do this, the terminal still effected by the "xclearcase" command, how could I type some commands now?
When you launch xclearcase, do so by adding a & to the end of it. This will make the shell send it to the background so you can do more stuff in your shell. E.g.
xclearcase &
That will allow you to further interact with your shell while xclearcase is running.
Also, if you're working in the terminal, I would recommend getting comfortable with cleartool for basic operations. For example, to checkout and edit a file:
cleartool co src/path/to/file.c
emacs src/path/to/file.c
Then, to checkin the file:
cleartool ci src/path/to/file.c
As Nemo mentions in the comments, the vc-clearcase Emacs mode allows you to checkout a file right from an Emacs session (C-x v v).
It will handle hijacked file, asking whether to keep the changes in said hijacked file through the question "Claim lock retaining changes?"
It will ask for a comment
It allows for checkouting a directory
It handle file with a -nocheckout rule on their config spec
I installed perl-support.vim into ~/.vim (unzipped). When I create a new .pl file it shows me the default template, which means my installation is successful (I guess). I have already added filetype plugin on in ~/.vimrc & /etc/vimrc.
How do I enter a perl-support command?
The write up recommends typing \isu in normal mode for creating a new sub, but the moment I hit i vim changes into insert mode and nothing intended happens.
What am I doing wrong?
Make sure you've enabled ftplugins with the filetype plugin on command in .vimrc, and of course make sure that the file you're editing is recognized as a Perl file (usually, by having a known extension, but you can force the matter by issuing the command set filetype=perl. If filetype plugins aren't enabled, or if the filetype isn't recognized, then the rest of perl-support won't get loaded at all.
As recommended by hobbs, set filetype=perl works.
However, I wanted to do this everytime I open a .t test file — which my vim does not recognize as perl files because the interpreter statement is also custom.
I checked out :help syntax in vim and saw this:
mkdir ~/.vim/ftdetect
cd ~/.vim/ftdetect
vim t.vim
which contains
au BufRead,BufNewFile *.t set filetype=perl
which means: if the file extension is .t then do set filetype=perl.
This can be useful for any other custom extension.
I found I had to install Perl::Tags before most things (esp. \ commands). Installing Perl::Tags made an error message thrown by filetype plugin on go away.
cpan> install Perl::Tags # make sure you say yes to any offer to install dependancies