Can I use environmental variables in find-file? - emacs

I'd like to use environmental variables in find-file command. Something like this:
C-x C-f $ENV_VAR/foo.txt
Does find-file have this functionality? What is the syntax?

As Barmar said, it works as you say... as far as you are not using ido or similar.
Type C-h k C-x C-f to know if you are using any enhanced wrapper for find-file, like for instance ido.
If you are using ido, you can type C-f in the prompt to revert back temporarily to the old plain find-file prompt, where you can type for instance $HO <tab> (to complete to $HOME), then write something like /.pro <tab> to complete to $HOME/.profile, etc.
If you were using another, you should check the documentation because they probably have a fallback method to.

Related

Why does Emacs local-set-key not overwrite a globally set key in mode hook?

In Emacs' tide-mode (typescript development) I would like to use M-q, which is normally bound to fill-paragraph, to rather run tide-format. I have a mode hook like
(defun setup-tide-mode ()
...
(local-set-key [M-q] 'tide-format)
(describe-key [M-q]))
(add-hook 'typescript-mode-hook #'setup-tide-mode)
When I open a typescript file I do see the *Help* buffer which indeed shows
<M-q> runs the command tide-format ...
Yet when I then run C-h k M-q to describe the key binding of M-q, I get
M-q runs the command fill-paragraph
There is this suspicious difference in the printout between <M-q> and M-q. This is probably telling me something, but I don't know what.
What would be the correct way to locally overwrite M-q to run a different command?
You want to use [?\M-q] instead of [M-q] because ?\M-q is the event generated when you press the Alt/Meta modifier along with the Q key.

How can I open multiple minibuffers in emacs?

Say I'm entering a command in the minibuffer, and I realize that I need to remember the path to some file as a param to my command. Can I instead of cancelling the command I started entering to do C-x d or to go to a shell, click (click? what's that?) on a secondary mini buffer to run such command?
You are looking for "recursive editing", specifically the bit discussed in the Recursive Minibuffer docs:
(setq enable-recursive-minibuffers t)
(minibuffer-depth-indicate-mode 1)
The latter line makes things the recursive editing less confusing, by showing the level of recursion. E.g C-x C-f then C-x b will appear like this:

Emacs: How to change "M-x" prompt to something else?

I have execute-extended-command bound to alt+a. So when in minibuffer, when i press it, the read-only prompt saying "M-x" is irrelevant for me. I want to change it to something else like "execute command:". How can i do that?
This prompt is hard-coded. You would need to either redefine read-extended-command, or advise completing-read (but that seems a fairly tenuous approach).
See M-x find-function RET read-extended-command RET
There are comments in the code referring to this very issue:
;; This isn't strictly correct if `execute-extended-command'
;; is bound to anything else (e.g. [menu]).
;; It could use (key-description (this-single-command-keys)),
;; but actually a prompt other than "M-x" would be confusing,
;; because "M-x" is a well-known prompt to read a command
;; and it serves as a shorthand for "Extended command: ".
Honestly, given the lack of a clean solution, I wouldn't bother trying to do this.
Check out smex, which is an improvement upon the built-in execute-extended-command; it allows you to customize the prompt via the variable smex-prompt-string.
Or, if you've got the Emacs source installed, you can jump straight to the implementation: just M-x find-function RET execute-extended-command RET

emacs create new file with ido enabled

I reciently switched to emacs starter kit which includes the ido package.
ido has a nice feature that suggests paths when find-file which is usually very handy except when trying to create a new file. When the new file name matches a suggestion in another path ido automatically switches to that path assuming that's what I wanted, but usually its not and I find it annoying.
To workaround the issue I either touch newfile from shell, create a new buffer and save as, or M-x find-file to get the original behavior. I could of course rebind C-x C-f to find-file again but must of the time I like ido-find-file, I just want it to stop automatically switching paths when I type the path explicitly.
I figure there is probably some simple key I can press during ido-find-file to tell it that the file I'm looking for does not exist and to stop making suggestions, or some var I can set to get more desirable behavior?
Try:
C-x C-f C-f
It should kick you out of ido mode into "normal" find file mode
C-j is the key combination you are seeking.
As mentioned: being fast, using C-j to confirm immediately, and using and additional C-f to temporarily switch to the traditional mode are all useful.
Also, when ido has already selected an alternate file path, you can hit C-z to return where you were and temporarily disable that behavior.
A solution for a related problem - ido not asking overwrite confirmation.
http://lists.gnu.org/archive/html/bug-gnu-emacs/2010-11/msg00226.html
On Fido, M-j does the trick.
It's bound to icomplete-fido-exit by default.

Emacs C-h c doesn't seem to work for chords 3 combinations long?

I'm trying to use C-h c in emacs to figure out what a key combination is bound to. The combination is C-u C-c C-q, which realigns tags in org-mode. However, Emacs just tries to look up C-u C-c and then fails. What am I doing wrong? I realize I could easily look at the orgmode source or something to figure this out, but for future reference what would I do to figure out what function something like this is bound to?
Edit: OK, so it's actually C-u followed by C-c C-q, and according to emacs this is what that combination is bound to:
(org-set-tags-command &optional arg just-align)
Call the set-tags command for the current entry.
So what exactly does it mean to give this command the argument 4?
Oh, just to give an explanation: I'm trying to start learning emacs-lisp and customization and one of the things I wanted to do was to have this command added to the before-save-hook so that when I save an org file, the tags get automatically aligned.
Final edit: I figured out why this command behaves as it does; given the prefix argument it changes its behavior. How can I set the prefix argument when calling the function in elisp?
It's not a general problem with combinations that are three keys long: For example, C-h c ESC ESC ESC (keyboard-escape-quit) or C-h c C-x r t (string-rectangle) both work fine.
When I try C-h c C-u C-c C-q in org-mode, the command interrupts after C-u and shows:
C-u runs the command universal-argument
in the minibuffer, which is correct. So, in fact, "C-u C-c C-q" is not a command, it's the command "C-c C-q" (org-table-wrap-region) started with an additional argument (4 -- see C-h k C-u for an explanation).