How do I use dired-read-file-name in Emacs? - emacs

I was looking for a method to show a list of filenames in a directory, and then select one of them.
I found this:
https://github.com/lawlist/dired-read-file-name and it seemed promising, so I copied it to my emacs direcory and tried:
(require 'dired-read-file-name)
but I get error
error: Required feature `dired-read-file-name' was not provided

require is not going to work because the source of dired-read-file-name.el does not have a provides expression. You might want to add:
(provide 'dired-read-file-name)
add the end of the file.
Alternatively, you can just load or more low-level load-file.
Also have a look at this.

Related

How can I tell if CEDET is using GNU Global?

I have CEDET working for the most part on emacs 24.2 with the latest from bzr
repository.
When I am searching for symbols or definitions, I see that the cedet mini-buffer
shows parses through a lot of files, some that are not there as header-files, the files
do not have any reference to the symbols I am searching.
I will leave CEDET to its job, let it search for symbols as it sees fit.
Is there any debug mechanism or verbose mode that I can turn on to see
1) What are all the files it is searching.
2) If it has found the GTAGS file at the base of my project. I understand that CEDET only
consults the GTAGS file to know about symbols.
I ask because there are some symbols that CEDET is unable to find the definition
for, but I'm able to find it from the gtags command line.
Thanks to Alex and Eric for their Numerous posts through-out the net.
This is a multi-step process.
First, make sure you've setup Global in the ways you want, such as via ede's locate feature, and through Symref.
Next, while visiting a file in a project you care about, use:
M-x cedet-gnu-global-show-root RET
to see if it can find a Global index file in that project.
Next, to see if symref found it, you need to eval this:
M-: (semantic-symref-detect-symref-tool)
and it will give you a symbol representing the tool it has chosen to use. It will say 'grep if it failed to use Global.
If you were in the middle of configuring things, you might need to reset things for you buffer. An easy way is to kill the buffer, and find it again, or:
M-x (setq semantic-symref-tool 'detect) RET
to force a detection again.

common lisp - get path to file

In Common Lisp, is there a way to get the path to a compiled file (something like current-directory)?
The file is not inside the current-directory folder.
This ought to be a comment but I'm going to give some code examples that might help the original poster along.
First of all, you need to be a little more clear about what you want to do. What is the problem you're trying to solve?
Secondly, here are a couple of examples which could be useful:
*default-pathname-defaults* usually set to the directory the CL image was started up in:
* *default-pathname-defaults*
#P"/Users/aerique/"
merge-pathnames allows you to construct new pathnames:
* (merge-pathnames "lib/misc" *default-pathname-defaults*)
#P"/Users/aerique/lib/misc"
* (merge-pathnames "lib/misc/" *default-pathname-defaults*)
#P"/Users/aerique/lib/misc/"
asdf:system-source-directory returns the path to a system loaded with ASDF:
* (asdf:system-source-directory :linedit)
#P"/Users/aerique/quicklisp/dists/quicklisp/software/linedit-20111203-git/"
Also see the linked ASDF manual for more useful file and system functions.
*load-truename* resp. *load-pathname* gives you what you need.
http://www.lispworks.com/documentation/HyperSpec/Body/v_ld_pns.htm
Perchance you want compile-file-pathname, which gives you the destination where compile-file would write into.
It'd help if you provide more context on what you're trying to achieve.
If you want get the pathname whitout use ASDF function, but you need also attend the users that use ASDF, you can use like this:
(defmacro project-pathname ()
(let ((path (or *compile-file-pathname* *load-truename*)))
`(progn ,path)))
It's necessary because the ASDF stores in one "/home/you/.../.cache/..." directory, and you need capture the pathname in compilation time with one macro.
You can use:
*default-pathname-defaults*
Please see http://cybertiggyr.com/gene/pathnames-0/node11.html

How do I use autoload to correctly load custom configuration?

I use the following structure in my emacs config: For each programming mode I use, I maintain configuration in a file called programming-mode-config.el. (So python configuration will go into python-mode-config.el etc).
Earlier, I used to require each of these files in my init.el. The drawback of this approach was that my start-up time was huge. So this weekend, I sat down and converted all the requires into autoloads. Now my init file looks like this:
(autoload 'python-mode "python-mode-config" "Load python config" t)
Thus python config will not be loaded until I open a python file. This helped bring down my start-up time to about 1 second, but it doesn't work properly in all cases. For example,
(autoload 'erc "erc-mode-config" "Load configuration for ERC" t)
does not load my erc tweaks at all. Looking at the autoload documentation, it states that:
Define FUNCTION to autoload from FILE.
...
If FUNCTION is already defined other than as an autoload,
this does nothing and returns nil.
So I'm guessing that the erc config is not loaded because ERC comes 'in-built' with emacs whereas python-mode is a plugin I use. Is there any way I can get my erc configuration to load only when I actually use erc? The only other alternative I see is using eval-after-load, but it would be rather painful to put every tiny bit of my customization into an eval-after-load.
I'm afraid it might also be that I haven't grokked autoloads properly. Any help would be appreciated.
autoload is intended to be used to load functions from a certain file, not to load additional functionality - which is what it looks like you're trying to do.
Use eval-after-load instead:
(eval-after-load "erc" '(load "erc-mode-config"))
That tells Emacs to load the erc-mode-config library after the "erc" file has been loaded - which is what you want. You could also use '(require 'erc-mode-config) if you have a provide statement inside of it.
The correct use of autoload is to load the actual file that contains the symbol. So, by having
(autoload 'erc "erc-mode-config" "Load configuration for ERC" t)
You were telling Emacs to find the function erc by loading the "erc-mode-config" library, which isn't where the erc function is defined. Also, the docstring is for the function in question, so the autoload statement above makes the help string for erc be "Load configuration for ERC" - which is also incorrect.
I'm guessing your first autoload example works because you have a (require 'python) statement in your config file... but that's just a guess.

Finding where varables have been declared in what file?

GNU Emacs 23.1.1
I am maintaining someones code. There are many files and directories for the headers and source files.
I am wondering if there is a easy way to use emacs that when I highlight a variable name I can go straight to where it is declared?
Some of the structures I am working in are declared in other header files, rather than go searching for them, I just want to be taken straight to them.
Many thanks for any suggestions,
Look into the etags command which builds a tags database. Once the tag DB is built and loaded, you can use M-. on any keyword to jump directly to the definition.
It's also pretty easy to hit C-h v RET on the variable name, to get its *Help*, then hit RET (or click) the file-name link to get to the source definition.

Emacs recursive project search

I am switching to Emacs from TextMate. One feature of TextMate that I would really like to have in Emacs is the "Find in Project" search box that uses fuzzy matching. Emacs sort of has this with ido, but ido does not search recursively through child directories. It searches only within one directory.
Is there a way to give ido a root directory and to search everything under it?
Update:
The questions below pertain to find-file-in-project.el from MichaƂ Marczyk's answer.
If anything in this message sounds obvious it's because I have used Emacs for less than one week. :-)
As I understand it, project-local-variables lets me define things in a .emacs-project file that I keep in my project root.
How do I point find-file-in-project to my project root?
I am not familiar with regex syntax in Emacs Lisp. The default value for ffip-regexp is:
".*\\.\\(rb\\|js\\|css\\|yml\\|yaml\\|rhtml\\|erb\\|html\\|el\\)"
I presume that I can just switch the extensions to the ones appropriate for my project.
Could you explain the ffip-find-options? From the file:
(defvar ffip-find-options
""
"Extra options to pass to `find' when using find-file-in-project.
Use this to exclude portions of your project: \"-not -regex \\".vendor.\\"\"")
What does this mean exactly and how do I use it to exclude files/directories?
Could you share an example .emacs-project file?
I use M-x rgrep for this. It automatically skips a lot of things you don't want, like .svn directories.
(Updated primarily in order to include actual setup instructions for use with the below mentioned find-file-in-project.el from the RINARI distribution. Original answer left intact; the new bits come after the second horizontal rule.)
Have a look at the TextMate page of the EmacsWiki. The most promising thing they mention is probably this Emacs Lisp script, which provides recursive search under a "project directory" guided by some variables. That file begins with an extensive comments section describing how to use it.
What makes it particularly promising is the following bit:
;; If `ido-mode' is enabled, the menu will use `ido-completing-read'
;; instead of `completing-read'.
Note I haven't used it myself... Though I may very well give it a try now that I've found it! :-)
HTH.
(BTW, that script is part of -- to quote the description from GitHub -- "Rinari Is Not A Rails IDE (it is an Emacs minor mode for Rails)". If you're doing any Rails development, you might want to check out the whole thing.)
Before proceeding any further, configure ido.el. Seriously, it's a must-have on its own and it will improve your experience with find-file-in-project. See this screencast by Stuart Halloway (which I've already mentioned in a comment on this answer) to learn why you need to use it. Also, Stu demonstrates how flexible ido is by emulating TextMate's project-scoped file-finding facility in his own way; if his function suits your needs, read no further.
Ok, so here's how to set up RINARI's find-file-in-project.el:
Obtain find-file-in-project.el and project-local-variables.el from the RINARI distribution and put someplace where Emacs can find them (which means in one of the directories in the load-path variable; you can use (add-to-list 'load-path "/path/to/some/directory") to add new directories to it).
Add (require 'find-file-in-project) to your .emacs file. Also add the following to have the C-x C-M-f sequence bring up the find-file-in-project prompt: (global-set-key (kbd "C-x C-M-f") 'find-file-in-project).
Create a file called .emacs-project in your projects root directory. At a minimum it should contain something like this: (setl ffip-regexp ".*\\.\\(clj\\|py\\)$"). This will make it so that only files whose names and in clj or py will be searched for; please adjust the regex to match your needs. (Note that this regular expression will be passed to the Unix find utility and should use find's preferred regular expression syntax. You still have to double every backslash in regexes as is usual in Emacs; whether you also have to put backslashes before parens / pipes (|) if you want to use their 'magic' regex meaning depends on your find's expectations. The example given above works for me on an Ubuntu box. Look up additional info on regexes in case of doubt.) (Note: this paragraph has been revised in the last edit to fix some confusion w.r.t. regular expression syntax.)
C-x C-M-f away.
There's a number of possible customisations; in particular, you can use (setl ffip-find-options "...") to pass additional options to the Unix find command, which is what find-file-in-project.el calls out to under the hood.
If things appear not to work, please check and double check your spelling -- I did something like (setl ffip-regex ...) once (note the lack of the final 'p' in the variable name) and were initially quite puzzled to discover that no files were being found.
Surprised nobody mentioned https://github.com/defunkt/textmate.el (now gotta make it work on Windows...)
eproject has eproject-grep, which does exactly what you want.
With the right project definition, it will only search project files; it will ignore version control, build artifacts, generated files, whatever. The only downside is that it requires a grep command on your system; this dependency will be eliminated soon.
You can get the effect you want by using GNU Global or IDUtils. They are not Emacs specific, but they has Emacs scripts that integrate that effect. (I don't know too much about them myself.)
You could also opt to use CEDET and the EDE project system. EDE is probably a bit heavy weight, but it has a way to just mark the top of a project. If you also keep GNU Global or IDUtils index files with your project, EDE can use it to find a file by name anywhere, or you can use `semantic-symref' to find references to symbols in your source files. CEDET is at http://cedet.sf.net
For pure, unadulterated speed, I highly recommend a combination of the command-line tool The Silver Searcher (a.k.a. 'ag') with ag.el. The ag-project interactive function will make an educated guess of your project root if you are using git, hg or svn and search the entire project.
FileCache may also be an option. However you would need to add your project directory manually with file-cache-add-directory-recursively.
See these links for info about how Icicles can help here:
find files anywhere, matching any parts of their name (including directory parts)
projects: create, organize, manage, search them
Icicles completion matching can be substring, regexp, fuzzy (various kinds), or combinations of these. You can also combine simple patterns, intersecting the matches or complementing (subtracting) a subset of them