Expand envvar in minibuffer - emacs

When the cursor is in minibuffer typing $ and then a few characters, say $HO offers envar name completion, for example running cygwin Emacs on Windows 7 it offers me $HOME, $HOMEDRIVE and $HOMEPATH. As well, typing a / after a complete variable name such as $HOME/ and tab shows files in that directory.
Is there a way to expand this variable? So that for example, I can delete part the expanded text and continue?
I am using iswitchb but I see the same behavior with emacs -q as well.
I am using cygwin build of Emacs 24.3.1 on Windows 7

Once you have chosen which of those variables you want, type a / afterwards, then press TAB.

Related

Setting up Emacs to run Scheme code

I have emacs 24.5 for windows installed, and when I try to run a scheme program in the buffer with C-x C-e it says run-scheme and when I hit enter it then says searching for program: no such file or directory, scheme. Looking around I have only found tutorials for unix systems, and downloading Linux is not an option for me at this computer. The other resources I have found were vague or unhelpful. I would really like to use emacs but so far I have not been able to use it at all
M-x customize-variable
Enter 'scheme-program-name'. Press Enter.
Replace 'scheme' with the path to your Scheme executable.
Click the 'State' button and select 'Save for Future Sessions'.
Or, you could add the path to your Scheme to Windows' PATH variable and only use its name in 'scheme-program-name'.
Or, you can edit your startup file by hand, but that's not really necessary.

Emacs shell behavior

I am using cygwin on windows 7. I have a question regarding the Emacs shell.
Whenever I use the shell inside of the Emacs(M-x shell)
It echo pwd directory after prints out the result.
I found it very annoying since it distracts me.
e.g.
$ ls
workspace
^[]0;~/cs61bl^G
myname#pc ~/cs61bl
Is there any way to remove these lines?
^[]0;~/cs61bl^G
myname#pc ~/cs61bl
When using Emacs, try using the eshell: M-x eshell. The eshell does not suffer from this problem.
You might be looking for "shell-dirtrack-mode". You can either do an M-x shell-dirtrack-toggle or (shell-dirtrack-mode 1) in your init file. Recent emacs versions seem to disable it by default.
There is this file http://www.emacswiki.org/emacs/setup-cygwin.el that simplifies setup of various packages in Emacs (including shell) to use cygwin. Also try not to use ANSI sequences in your PS1 prompt because Emacs shell mode wouldn't interpret them, something like
export PS1="\h \W\$ "
should do.

Filtering ZSH history by command

I was told that in ZSH you could do something like command and then when you hit up it would filter the history based on the given command. But when I try this it just cycles the history like bash does. Is this disabled by default?
Hit Ctrl+R, type some letters, it will find the previous command with these letters, keep hitting Ctrl+R to continue through the previous findings.
Works in bash, zsh (and other shells i suppose).
What i personally like to have is: type some letters, press Up, the previous commands starting with the same letters appear. Very powerful, i love it.
You have to bind the keys you want to history-beginning-search-backward and history-beginning-search-forward.
In case it's not enough for you, zsh has a lot of options, try to look in Zsh Line Editor and tell us.
For bash, less powerful but more common, Bash commands for history.
Use exclamation point:
> !<starts-with this string>
You can arrow up/down through all commands that started with that. I use "!v" all the time to get my previous command for opening a file with Vim.
You can also use a question mark to search beyond matching the beginning of the string,
> !?status
Can find "git status".
Use percol to dynamically search and navigate through your history with Ctrl-r.
install percol: sudo pip install percol
add the zsh-history-search code snippet to your .zshrc file.
After a Ctrl-r, you can see your whole history in the same window. Searching for a keyword (dynamically) narrows that list down. You can use key-bindings (like this emacs like config) to navigate up and down the list and eventually make a selection.
Here is a search for all sudo install commands available in history with sudo make install selected.
Enter issues the selected command.
We can also use fzf to fuzzy search the command history interactively.
Here is how to install:
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
Say yes to all its configs. After that, restart your zsh shell, and press Ctrl-R, whoa, interactive command history search pops up. Enjoy!
With the vim keybindings activated in zsh you can use vi-history-search-backward (/) when in vi command mode.
That's a feature available in fish, but it seems like someone made a zsh plugin for it. It's not available in standard ZSH.
If you don't want to add any keybindings, you can search by default using Ctrl+R to move backward & Ctrl+S to move forward.
You can start search with any of the key shortcuts Ctrl+R or Ctrl+S

.emacs Edit to Always Start Emacs in Terminal Mode?

I use emacs as my editor-of-choice, and since I'm doing a lot of work in a terminal I always run emacs as
emacs -nw
so that it runs in the terminal instead of in a window.
I'd like to just run emacs and have it know that it should run in a terminal. My question is - how do I edit my .emacs file so that this is the default behavior?
You can't do this in the .emacs file. By the time that file is being parsed, the "chosen" emacs binary is already running.
You can install the emacs-nox package as one commenter suggests, or create an alias in your shell so that "emacs" is always treated as "emacs -nw".
Randy
I'm using a bash alias instead of .emacs to do that.
Add this line to your ~/.bashrc.
alias emacs='emacs -nw'
There is any easy way to solve the problem in general that has nothing to do with emacs at all and will work for any program that can choose between running in the console vs X:
unset DISPLAY
Of course you may not want to put that in your configuration file to be applied globally to all your shell sessions, so if you want it to apply to only emacs, then either call it from the command line like this:
DISPLAY= emacs
note the space!!! if you leave the space out it means you're setting the DISPLAY to emacs instead of setting DISPLAY to nothing... this command is a shorthand for:
DISPLAY=; emacs
So either use the above from the command line(s) or put that in a wrapper script that would look something like this:
#!/bin/bash
unset DISPLAY
exec emacs
I recommend the exec there because it will replace your wrapper script with emacs; to see the difference between the two you can run:
pstree -p
When I was first setting up a "emacs -nw" alias for emacs in windows I got stuck in a situation where I thought tototoshi's explanation hadn't worked. Yet all that was required was a restart of my terminal. Therefore, i think its worth mentioning that in windows (at least) if you are using emacs within the git bash terminal to create the .bashrc file and add "alias emacs='emacs -nw" to it (as tototoshi mentions) you have to close and reopen your terminal for it to work.

Changing the default folder in Emacs

I am fairly new to Emacs and I have been trying to figure out how to change the default folder for C-x C-f on start-up. For instance when I first load Emacs and hit C-x C-f its default folder is C:\emacs\emacs-21.3\bin, but I would rather it be the desktop. I believe there is some way to customize the .emacs file to do this, but I am still unsure what that is.
Update: There are three solutions to the problem that I found to work, however I believe solution 3 is Windows only.
Solution 1: Add (cd "C:/Users/Name/Desktop") to the .emacs file
Solution 2: Add (setq default-directory "C:/Documents and Settings/USER_NAME/Desktop/") to the .emacs file
Solution 3: Right click the Emacs short cut, hit properties and change the start in field to the desired directory.
You didn't say so, but it sounds like you're starting Emacs from a Windows shortcut.
The directory that you see with c-x c-f is the cwd, in Emacs terms, the default-directory (a variable).
When you start Emacs using an MS Windows shortcut, the default-directory is initially the folder (directory) specified in the "Start In" field of the shortcut properties. Right click the shortcut, select Properties, and type the path to your desktop in the Start In field.
If you're using Emacs from the command line, default-directory starts as the directory where you started Emacs (the cwd).
This approach is better than editing your .emacs file, since it will allow you to have more than one shortcuts with more than one starting directory, and it lets you have the normal command line behavior of Emacs if you need it.
CWD = current working directory = PWD = present working directory. It makes a lot more sense at the command line than in a GUI.
I think the line you need to add to your .emacs is is
(setq default-directory "C:/Documents and Settings/USER NAME/Desktop/" )
Emacs will start in your desktop that way, unless you have a file open. It will usually start in the same directory as the file in your current buffer otherwise.
You can type the 'cd' emacs command. ( M-x cd ) to change the default folder as a one off.
I've put
(cd "c:/cvsroot/")
in my .emacs and it did the job
The default folder is actually the same as the current working folder for the buffer, i.e. it can be different for every file you work with. Say that the file you are working with is located in C:\dir_a, then the working directory for that buffer will by default be C:\dir_a. You can change this with M-x cd and type in whatever directory you would like to be the default instead (and by default I mean the one that will show up when you do C-x C-f).
If you start emacs without opening a file, you will end up with the *scratch* buffer open. If you started emacs from a Windows shortcut, the working directory will be the same as that specified in the shortcut properties. If you started it from the command line, it will be the directory from where you started it. You can still change this default directory with M-x cd, also from the *scratch* buffer.
Finally, you can do as Vadim suggests and put
(cd "c:/dir_a/")
in your .emacs file, to make that directory the default no matter how you start emacs.
As you're on Windows you can do it with a shortcut.
Create a shortcut to C:\emacs\emacs-21.3\bin\runemacs.exe. Edit the properties of the shortcut and change the value of Start In: to be whatever you want your default directory to be.
I am using emacs 22.2.1 under Windows XP and have been helped by the answers above to get the response in the minibuffer I want to the command C-x C-f. Initially I was getting
"Find file: C:\Program Files\emacs\bin/" like Anton.
I have HOME set to "C:\Documents and settings\USER NAME\My Documents".
The response to C-x C-f I want in the minibuffer is "Find file: ~/".
By adding (setq default-directory "C:/Documents and Settings/USER NAME/My Documents") to my .emacs file I was able to get the response "Find file: C:\Documents and settings\USER NAME\My Documents/" which is functionally the same as "Find file: ~/".
However, I noticed one further point. "Customize Emacs" under "Options" allowed me to inhibit the startup screen. Now when I open emacs I go immediately to the scratch buffer. When I type C-x C-f in the scratch buffer I get the exact response I want.
I have added to my shortcut (in Gnome, Linux) a pramater which is a blank dummy file name, and I specify the directory. Since my emacs defaults to "home" I simply say:
/Desktop/blank_file
and that opens a file called "blank_file"
That also moves the current working directory for that emacs session to the desktop.
If I happen to put stuff in "blank_file" then save it, of course, I've got that stuff saved. Which might be an annoyance or it might be a good thing, depending!
To change default directory to DESKTOP in Dired and shell put this in your ~/.emacs:
;;This works for Windows XP.
(setq default-directory (concat "C:\Documents and Settings\MY_ACCOUNT\DESKTOP\"))
For windows users, the best way that I found is to create the shortcut for runemacs.exe and placing the shortcut in the root directory of my notes folder.
This way, when you use this shortcut to open emacs, it will by default open in the root directory without having to specifically set the Start In property (you can leave the Start In property blank).
Reference: According to Microsoft, if you leave the 'Start In' box empty, the script will run in the current working directory
TIP:
Additionally, if you have organized your notes into multiple root folders (Personal, Work etc...), you can copy multiple such shortcuts in each folder to open various instances of emacs with their own default directories.
In Windows 8, it works to create a shortcut in the Desktop and change the property 'Start In:' for the shortcut.
Now, I ran the program emacs-23.3\bin\addpm.exe as recommended, and the Windows-8 screen (that horrendous invention from Microsoft) it appeared an icon-link to Emacs. But there you have to change again the property 'Start In'. (It is different from the one in the desktop).
Just right-click, choose in the bottom bar 'Open the file location' (or similar, I did it in my language), and you are taken to the folder with a new shortcut, in which you can (must) also change the property 'Start In:'.
A little involved, but in fact very easy.
Since the most annoying thing is having windows Emacs dump you into system32 when you are just using the shortcut, but want every other case to work, just use a bit of elisp...
(when (string< "C:\WINDOWS\system32" default-directory) (setq default-directory "~/"))
So it will only default to your home directory when you end up in system. The only drawback is if you really want to start emacs in system32...