Emacs: Using ffap and ido-mode together - emacs

I used to work with find-file-at-point to open files, URLs etc. My .emacs contains
(require 'ffap)
(ffap-bindings)
I discovered ido-mode and I tried to use it with
(ido-mode 1); enable ido-mode
(setq ido-enable-flex-matching t); flexibly match names
(setq ido-everywhere t); use ido-mode everywhere, in buffers and for finding files
(setq ido-use-filename-at-point 'guess); for find-file-at-point
It turns out that C-x C-f for finding a file does not activate ido-mode (I do not see the typical suggestions of file names as I do for buffers when doing C-x b). When I comment out the two lines related to ffap, it works as expected, however, I would like to use ffap as well.
Is this possible?
Assume the point is on an URL. It would be great if C-x C-f C-f (the fallback to the "old" completion style) would activate ffap and thus offer to open the URL.

Yes -- you need to rebind the functions that you use.
You look inside ffap at the functions that you need , and rebind them like that:
(global-set-key [end] 'function)
(you change the end key with your combination).
There are many ways to rebind a key, but first of all start looking at the functions that are useful for you inside ffap.

Related

Emacs: disable automatic file search in ido mode

I use ido mode. Here is how I set in .emacs
(require 'ido)
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode t)
When I open a file, I do C-x C-f my_file and if it doesn't exist in current directory, emacs will try to search for it in other recent used directories in about a second. However, most of the time I was just trying to create new files. I had to type the file name really fast and then C-j to confirm it. How can I stop ido from doing this?
The following will completely disable the feature:
(setq ido-auto-merge-work-directories-length -1)
I've never seen any value in it, so disabling it completely might make sense for a lot of people.
Here is another option using Ido:
Type C-x C-f as usual.
Find the directory you want to create the new file in using Ido search.
At any moment type C-f again, and Emacs will go back to the old find-file functionality.
You can then type the file name you want and Emacs will create a new buffer. So, if you type C-x C-f C-f file_name RET it will create a buffer called file_name temporarily in the current directory.
I found an easy solution:
(setq ido-auto-merge-delay-time 9)
The time here is in seconds. I could set a very large number to completely disable this feature.

emacs command-t behavior

I'm a total emacs newbie. I watched a video which shows ido in emacs working similar to command-t in textmate:
(video is: http://vimeo.com/1013263)
The issue is I don't get this behavior when I'm in emacs with ido mode. Here is my init.el:
(require 'ido)
(ido-mode t)
(setq ido-enable-flex-matching t)
I have no idea what t means, this is just what I found online.
When I search for a file (C-x C-f) it doesn't find files in sub directories. So if I have a file test/core.clj and I search for tc (for test core) it has no match.
On thing I notice is that he has 'Project file:' in the screenshot, where I get 'Find file:'. I installed 'find-file-in-project' to see if that was the missing behavior but it doesn't work either. It only does matching on the filename, not the directories containing the file.
ido 'learns' what files you've visited and maintains a history cache. I believe that's what you're seeing in the screenshot above.(sometimes you'll want to clear the cache with ido-wash-history).
Usually once you've been in a project for a while it'll work in the way you're expecting.
If you're new to emacs, customize is the best way to experiment with the various features. e.g. you can M-x customize-group <RET> ido <RET> and see all the options for ido
There are other options, like find-file-in-project, are you sure you're actually invoking it? Just installing it isn't enough, that won't re-bind C-x C-f for you.
Try M-x find-file-in-project and see if that's the behaviour you desire.
There's also find-file-in-repository if you always work in source controlled dir.
('t' means true btw).
I would take a look at find-file-in-project.el.
http://www.emacswiki.org/cgi-bin/wiki/FindFileInProject
It will search for all files within the .git tree. I have this mapped to C-c f.
the "t" just means non-nil or true. You could use "a", "w", or "t" and it would mean the same thing. People just use t by convention.
Enabling
If you want to enable something you would have in your .emacs (ido-mode t)
Disabling
If you want to disable something you would have in your .emacs (ido-mode nil)

Shortcut to open a specific file in Emacs

I want to be able to use a keyboard shortcut to edit my .emacs file instead of typing Ctrl-XCtrl-F.emacsEnter every time (here's an analogous question regarding Vim). There's probably an obvious way of doing this, but I can't find the Emacs Lisp command to open a file. I'd think it would be something beginning with "open" or "file" but typing M-x and those terms doesn't seem to bring up anything relevant. I tried
(global-set-key (kbd "<f6>") (find-file "~/.emacs"))
but that doesn't work.
According to the documentation
(global-set-key KEY COMMAND)
Give KEY a global binding as COMMAND. COMMAND is the command
definition to use; usually it is a symbol naming an
interactively-callable function.
So you have to use an interactively-callable function:
(global-set-key (kbd "<f6>") (lambda() (interactive)(find-file "~/.emacs")))
Personally I prefer to use emacs registers to store files which I use often.
I would store '~/.emacs' in a register:
(set-register ?e (cons 'file "~/.emacs"))
and open it with C-x r j e
Bookmarking is an excellent solution for this purpose that is packaged with emacs.
That way if it's ok for you to see the list of files that you want to open, you can easily browse them. There is also BookmarkPlus which offers variety of options.
M-x list-bookmarks

Reload .emacs for all active buffers

A question already has been asked how to reload a .emacs file after changing it.
The proposed solutions were to use M-x load-file or M-x eval-region RET on the changed region.
Neither of these solutions affect other open buffers for me. Is there a way to reload the .emacs file for all open buffers?
I should also note that the M-x load-file does not have the desired effect for reasons outlined in the comments to that answer.
Your .emacs file is a global configuration that gets evaluated once only. It does not get applied to each buffer individually.
How you actually achieve what you want is really going to depend on what those .emacs changes are. Some elisp will only take effect the first time it is evaluated; or when a buffer changes major modes; or when a file is loaded; etc, etc...
If you want to reload some or all of the file buffers, ibuffer makes that pretty easy:
M-x ibuffer RET to start ibuffer (I recommend binding this to C-xC-b).
/f.RET to filter by filename regexp . so as to match any filename.
m (on [default]) to mark all filtered buffers.
V (uppercase) to revert all marked buffers.
or you could replace steps 2+3 with M-x ibuffer-mark-by-file-name-regexp RET . RET. You may wish to bind that command to *f:
;; Bind `ibuffer-mark-by-file-name-regexp' to *f
(eval-after-load "ibuffer"
'(define-key ibuffer-mode-map (kbd "* f") 'ibuffer-mark-by-file-name-regexp))
type *c-h to see all the other ibuffer-mark-* commands which are bound by default.
This may strike you as brute force, but
it will certainly reload your init file (consider alternatives to .emacs)
it will reload all open buffers (provided you are using desktop, which you should)
it is easy
C-x C-c
emacs --debug-init &

Don't show uninteresting files in Emacs completion window

How do I prevent Emacs from showing me all the files I'm not interested in (such as ~ backup files, .pyc files, or .orig files) when I: C-x C-f TAB ?
It is working in one respect: if I know the file I want to open begins with foo and I type foo TAB then the mini-buffer correctly autocompletes all the way to foo.py. It correctly ignored foo~ and foo.pyc, because both ~ and .pyc are in completion-ignored-extensions. It also correctly lets me open either ignored file if I really want to by typing in all the letters my self.
However, if I just hit TAB to to bring up the completion list buffer then that list includes files with extensions in completion-ignored-extensions, which makes it very difficult to find what I'm looking for.
Clearly the code to ignore uninteresting files is there and working. How do I get the completion list buffer to respect completion-ignored-extensions?
(by-the-by, can I make dired behave similarly?)
This piece of advice filters out files with extensions listed in 'completion-ignored-extensions:
(defadvice completion--file-name-table (after
ignoring-backups-f-n-completion
activate)
"Filter out results when they match `completion-ignored-extensions'."
(let ((res ad-return-value))
(if (and (listp res)
(stringp (car res))
(cdr res)) ; length > 1, don't ignore sole match
(setq ad-return-value
(completion-pcm--filename-try-filter res)))))
Note: This doesn't affect dired.
For the dired issue, add this to your .emacs
(eval-after-load "dired"
'(require 'dired-x))
(add-hook 'dired-mode-hook
(lambda ()
(dired-omit-mode 1)))
Read the documentation for dired-x to get an idea of what's available there.
I would recommend using ido-mode to ignore files; it comes with Emacs by default and adds many other useful enhancements that you'll quickly learn to love. The Ignorance is Bliss section from this Mastering Emacs blog post covers how to ignore files, directories, and buffers:
ido-ignore-buffers Takes a list of buffers to ignore in C-x b
ido-ignore-directories Takes a list of directories to ignore in C-x d and C-x C-f
ido-ignore-files Takes a list of files to ignore in C-x C-f
Icicles does what you expect by default. It always respects completion-ignored-extensions for file-name completion, including for buffer *Completions*. And you can toggle this ignoring on/off at anytime, by hitting C-. in the minibuffer.
In addition, if you use library completion-ignored-build.el by Kevin Ryde, then Icicles automatically takes advantage of that library's dynamic adjustment of ignored file extensions. (Just load completion-ignored-build.el -- do not enable its minor mode or advice.)
I don't know of an answer for completion, I'm afraid. I think this is by design - when you know the name you're looking for, you probably don't want e.g. the backup file. But when you don't know, it's probably better to have a list of all of the files.
However, for dired, you can load the 'dired-x' package on startup (in your .emacs), and this provides dired-omit-mode:
(load "dired-x")
You can use 'M-x customize-variable<RET>dired-omit-files' to set the actual patterns to ignore. Then when you are in dired mode you can use M-O (the letter, not the number) to toggle 'omission' on and off.