Function Definition - Don't know how to find - emacs

I use SlimeNav to read elisp code. It works good mostly, but for inbuilt functions, at times, it does not work.
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
In this snippet, when i press Alt + . on local-file function, it says,
Don't know how to find 'local-file'

local-file is not a function anywhere in the core. It's used as a let-bound variable 7 times though.
Maybe you confused it.

Also remember that when accessing the documentation on a function (eg with C-h f), you should see a link you can click to get to the source code. Works also with the C sources if they are available in a way Emacs can find.
As an example, the documentation for find-file looks like this:
find-file is an interactive compiled Lisp function in `files.el'.
It is bound to <open>, C-x C-f, <menu-bar> <file> <new-file>.
(find-file FILENAME &optional WILDCARDS)
Edit file FILENAME.
...
You should be able to see that `files.el' comes out in a different colour, this you can click and it will bring you to the definition of that function.

Related

How does the "pdf-tools" package overrides "dired-find-file" method?

After installing pdf-tools the dired mode opens the pdf file with PDFView mode as major mode.
(use-package pdf-tools
:ensure t
:config
(pdf-tools-install t))
How does the pdf-tools package be able to accomplish this?
The Help for RET key in dried buffer says it is bound to dired-find-file
RET (translated from ) runs the command dired-find-file (found
in dired-mode-map), which is an interactive compiled Lisp function.
I searched for dired-find-file in pdf-tools installed elisp files and could not find any advice-add's?
Also please explain how can one go about finding arbitrary key bindings like this one?
What it modified is not directly related to dired, but to how Emacs decides to open files in general. The part of the code that is responsible for that is in pdf-tools-install-noverify, itself called by pdf-tools-install. The first two lines of the function are:
(add-to-list 'auto-mode-alist pdf-tools-auto-mode-alist-entry)
(add-to-list 'magic-mode-alist pdf-tools-magic-mode-alist-entry)
the relevant variables pdf-tools-<auto/magic>-mode-alist-entry being constants defined earlier in the file pdf-tools.el.
You can check the relevant documentation for auto-mode-alist and magic-mode-alist, but to sum up, the former is a mapping from "filenames" (or more precisely, file patterns -- typically, regexps matching file extensions) to major modes, and the latter is a mapping from "beginning of a buffer" to a major mode (see also this wikipedia page on magic numbers/file signatures).
As to how one can determine that: because it is not directly related to key bindings/advices/redefinition of functions, the only "general" option is to explore the "call stack" ! The package tells you to put (pdf-tools-install) somewhere in your init file to activate the package, so you can try to see what this function actually does -- and going a bit further, you see that it is essentially a wrapper around pdf-tools-install-noverify, which does the real job of setting everything up.

How to extend Neotree to open a file using hexl?

I'm trying to extend Neotree to open a file using hexl-mode with the shortcut C-c C-x. How would one do this?
I've tried to evaluate a key definition after the Neotree load where it uses my/neotree-hex to open a file path using neo-buffer--get-filename-current-line.
(defun my/neotree-hex
(hexl-find-file neo-buffer--get-filename-current-line))
(with-eval-after-load 'neotree
(define-key neotree-mode-map (kbd "C-c C-x")
'my/neotree-hex))
At the very least, you are missing the (empty) argument list in the function:
(defun my/neotree-hex ()
(hexl-find-file neo-buffer--get-filename-current-line))
I don't know what neo-buffer--get-filename-current-line is: if it is a function, then you are not calling it correctly - in lisp, you call a function by enclosing the (name of the) function and its arguments in parens: (func arg1 arg2 ...)[1]; so if it is a function and it takes no arguments, then your function should probably look like this:
(defun my/neotree-hex ()
(interactive)
(hexl-find-file (neo-buffer--get-filename-current-line)))
In order to be able to bind it to a key, you have to make your function a command, which means that you need to add the (interactive) form.
Disclaimer: I know nothing about neotree.
[1] You might want to read an introduction to lisp. One (specifically tailored to Emasc Lisp) is included with the emacs documentation, but is also available online. Eventually, you will want to read the Emacs Lisp Reference Manual. Calling a function is covered in the Introduction and is covered in detail in the Reference.

Emacs org-mode tags not found

I'm learning to use emacs and org-mode. I create a few tags, in a .org file, as such :outline: lets say.
And then searched for them using:
C-c a m outline
C-c a t outline
C-c \ outline
And the output is always (basically, did't find anything):
Headlines with TAGS match: outline
Press `C-u r' to search again with new search string
What am I doing wrong. Can someone please tell me what I'm missing?
Thanks in advance.
Common problems when initially setting up org-mode include, but are not limited to, properly configuring the org-agenda-files variable. A user may choose to have one or more files, or a directory.
Here is an example of multiple files:
(setq org-agenda-files
(list "~/org/gtd.org" "~/org/work.org" "~/org/personal.org"))
Here is an example of a directory:
(setq org-agenda-files (list "~/"))
(setq org-agenda-file-regexp "\\`[^.].*\\.org\\|.todo\\'")
It is interesting to note that there is also non-interactive function with the same name, which looks up the configuration of the org-agenda-files variable -- the function is what org-mode generally relies upon when any other function looks up the value of the variable. To see an example of how that non-interactive function works, the user can do something like this:
M-x eval-expression RET (org-agenda-files) RET
The importance of setting the org-agenda-files variable can be seen by examining the function org-match-sparse-tree, which in turn calls org-scan-tags using org-make-tags-matcher, which uses org-global-tags-completion-table, which uses the function org-agenda-files, which uses the variable org-agenda-files. If the variable org-agenda-files is not set up correctly, a tags search and auto-completion of tags will not work correctly.
Another common issue arises when the variable org-tag-alist has not yet been properly set up -- here is a link to the manual page on that issue: http://www.orgmode.org/manual/Setting-tags.html

Emacs - how to see/how to debug a single elisp function/emacs command

There is one thing that I don't like on table function in Org-mode for emacs. I would like to see all the functions that get executed by function that I run as Emacs command.
What is the best way to do that? Any tips how to get started with debuging elisp code, especially single command of interest?
C-hf function name to find the source code for the function.
C-uC-M-x to instrument the function for Edebug.
Whenever the function is called, Emacs will drop into Edebug which makes it easy to execute the function step by step, inspect variables, and do other typical debugging tasks. See (info "(Elisp)Edebug") for more information.
I prefer the traditional Emacs debugger to edebug. To use it:
M-x debug-on-entry the-function RET
Then, whenever the-function is invoked, the debugger is entered. Use d to step through the evaluation, and c if you want to skip through a step (not dive into its details.
It helps to view the definition of the-function in another window/frame while you step through it.
You can cancel debug-on-entry using M-x cancel-debug-on-entry.
C-h f to go to function help mode, then type the name of the function. If it is an elisp function, you can then view the source and look for yourself what functions it calls.
If you want a programmatic way to see the source of a function (akin to Clojure's source macro) you can use the symbol-function subroutine.
For instance, there is a defun do-math in my .emacs file. To see its source, I can do the following
(symbol-function 'do-math)
and it gives me
ELISP> (symbol-function 'do-math)
(lambda
(expression)
(interactive "sexpression:")
(insert
(number-to-string
(eval
(read expression)))))
See also :
https://www.gnu.org/software/emacs/manual/html_node/elisp/Function-Indirection.html
See also also :
http://ergoemacs.org/emacs/elisp_symbol.html

Opening definition of Emacs command

is it possible to open in emacs elisp file with command definition, to see, how it is defined?
Yes you can call M-x find-function
Some functions are implemented in C. To be able to find C function you have to download C sources (if you have not yet done so) and add the following line to your .emacs
(setq find-function-C-source-directory "/path/to/c-source")
Another way:
C-h f foo RET to see the documentation for the function foo.
The documentation will tell you, on the first line, where and how the function is defined. Click the link (or hit RET with cursor on it) to the source file where the command is defined. You have to have the Lisp sources (for Lisp code) or the C sources (for C code) installed on your system in order for this to work.
You can also start from a key, without knowing what its command is: C-h k.