Run emacs lisp script - debugging

I found the script and i need run it.
I tried to run it like this (i used eval-buffer command):
(require 'subr-x)
(require 's)
(load-file "~/git-graph.el")
(require 'git-graph)
(git-graph/to-graphviz-pretty
"git"
(git-graph/git-graph-head
"E:/GitStack/repositories/gitRepo.git"
"master"))
But get an error:
Loading e:/emHome/git-graph.el (source)...done
let*: Symbol’s function definition is void: first
picture
Please tell me what is wrong. And how i can run this script?
I'm new to this.

Why are you loading library git-graph twice?
What happens if you just remove either the load-library line or the require line -- do you still get an error?
With your original code, insert this line after the load-library line:
(message "After load-library")
And insert this line after the require line:
(message "After require")
See which message(s) you get: check buffer *Messages*. That should tell you which attempt to load the library (if either) led to the error. Maybe look for the text first in the library, to see if you notice anything funny.
If it doesn't look like the problem comes from loading that library then it likely comes from the expression after your require.
Do M-x toggle-debug-on-error, then do your M-x eval-buffer, and post the *Backtrace* output here. That will show us just where the error is raised.
You can also try M-x debug-on-entry git-graph/to-graphviz-pretty and step through the debugger using d (or c to skip details of a given step). That will eventually show you which code raised the error.

Related

How to debug? emacs lisp program behavior does not achieve the desired but the executing the same as command does?

In a test buffer in emacs with Spacemacs, I have the following (the problem is also described in the buffer content):
* Top Heading
** A subheading created by executing commands
M-x org-insert-heading
M-x org-do-demote
Below I tried to achieve the same with an elisp function:
*** A subheading created by executing an interactive elisp function still works
It also works. Here is the program:
(defun org-insert-subheading-relative ()
"Replacement of org-insert-subheading, as it requires to provide an argument,
which is not convenient to program."
(interactive)
(org-insert-heading)
(org-do-demote)
)
However, having the code segment below,
the (org-do-demote) would not work, in
the following code segment:
(progn
(goto-end-of-code-block)
(insert "\n")
(org-insert-heading)
(org-do-demote)
(insert block)
(hide-subtree)
)
What could be the cause of the problem?
Here is the related code not defined by standard emacs:
(defun goto-end-of-code-block ()
(re-search-forward "#\\+END_SRC.*$" nil t 1) ; no raising error
)

How to debug `Error while processing function` in `vim` and `nvim`?

TL;DR
How to find where exactly vim or nvim error started (which file?) when I'm interested in fixing the actual issue and not just removing the bad plugin? Anything better than strace and guesswork to find the error origin?
Issue
I often add a plugin to my vim or nvim config and end up getting errors on hooks (buffer open, close, write):
"test.py" [New] 0L, 0C written
Error detected while processing function 343[12]..272:
line 8:
E716: Key not present in Dictionary: _exec
E116: Invalid arguments for function get(a:args, 'exec', a:1['_exec'])
E15: Invalid expression: get(a:args, 'exec', a:1['_exec'])
The problem is, I have no idea where those come from, only get some line number of unknown file and I know it's not my vim/nvim config file.
Somewhere, you have a plugin that has defined a dictionary with anonymous-functions (check the help related to this tag).
For the curious ones, it's done this way:
let d = {}
function! d.whatever() abort
throw "blah"
endfunction
When you execute this function, you'll get the kind of error you're currently observing. That's why I stopped working this way to prefer:
let d = {}
function s:whatever() abort
throw "blah"
endfunction
let d.whatever = function('s:whatever') " a workaround is required for older versions of vim
" At least this way I'll get a `<SNR>42_whatever` in the exception throwpoint, and thus a scriptname.
That's the why. Now, back to your problem, AFAIK, the only things you'll be able to know are the two functions that have been called:
in line 12 of :function {343}, you've called
:function {272} which contains an error at line 8.
Thanks to these two commands (may be prefixed with :verbose, I don't remember exactly), you'll get the source code of the two functions, which you should be able to use in order to grep your plugins to know where it appears.

Emacs shell script mode hook

For some reason my shell script mode hooks do not get executed. Example in my .emacs:
(add-hook 'shell-script-mode-hook (lambda ()
(rainbow-delimiters-mode 1)))
causes the variables to be set, but the mode is not loaded for the opened script files. What is the proper way to hook here?
I use the default shell script mode (modeline says e.g. Shell-script[bash]). Do I have to hook for each shell type individually (sh, bash, zsh)? If yes can you please tell me how?
Thank you very much!
EDIT3:
It turned out to be due a conflict of textmate-mode with the skeleton-pair-insert in sh-mode (I tried to avoid the conflict by disabling textmate in sh-mode, which then left the sh-mood-hook aparatus in ruins. I've removed textmate-mode completely and use now the standard skeleton-pair approch globaly.
I'll accept phils answer - without him I'd probably not be able to debug this on my own.
EDIT2:
Thanks to phils, I think his comment takes us closer to solution. It's not a problem with rainbow-delimiters though. I removed all sh-mode-hook except your hello message one and restart Emacs. When I open a .sh file I get this:
Setting up indent for shell type bash
setting up indent stuff
Indentation variables are now local.
Indentation setup for shell type bash
File mode specification error: (void-function nil)
Note no "hello" message. The value of sh-mode-hook is:
(nil
(lambda nil
(message "hello")))
I think the problem is this first nil value - though I don't see that it would be set anywhere.
If I eval this:
(setq sh-mode-hook t)
(add-hook 'sh-mode-hook (lambda () (message "hello")))
I see the hello message, though after restart (I've put those lines in .emacs) it is gone again (the nil is again on top of the hook).
Any idea what to do to have active hook at setup?
EDIT1:
I've tried also:
(add-hook 'sh-mode-hook (lambda ()
(rainbow-delimiters-mode 1)))
with same negative result - not sure if this is relevant though...
shell-script-mode is an alias for sh-mode. I haven't checked, but I would suspect that only the hook variable for the 'real' function name is evaluated, so I think sh-mode-hook would be the one to use.
Anyhow, there's nothing broken about your syntax, so there may be something amiss with the use of (rainbow-delimiters-mode 1). For instance, you should be able to observe that the following works correctly:
(add-hook 'sh-mode-hook (lambda () (message "hello")))
FWIW, for hooks I recommend not using anonymous functions at all, simply because it's much easier to update your hook function if it is named (removing the old lambda expression from the variable before adding an updated one is just annoying in my books).
Try to remove ':
(add-hook 'shell-script-mode-hook (lambda () (rainbow-delimiters-mode 1)))

How can I get 'next-error' to copy the line causing the error into the kill-ring?

I tried running
(list (next-error)
(kill-ring-save (line-beginning-position) (line-end-position)))
immediately after M-x compile
But it pushes the current line to the kill ring, not the line where the error was found...
If so how do I make emacs wait for (next-error) to complete before continuing with the next command?
This little bit of advice will copy the line specified by the error into the kill ring:
(defadvice compilation-goto-locus (after next-error-copy-offending-line activate)
(kill-ring-save (line-beginning-position) (line-end-position)))
If you decided you wanted to grab the error message, you could use this:
(progn
(next-error)
(with-current-buffer next-error-last-buffer
(kill-ring-save (line-beginning-position) (line-end-position))))

Modify mode-compile.el to handle MS-Windows paths with imbedded blanks?

Can anyone suggest a modification of mode-compile.el that will make it work better on Windows? My specific issue is handling of path names that contain blanks. I'm working on code in Ruby, using "GNU Emacs 22.2.1 (i386-mingw-nt5.1.2600) of 2008-03-26 on RELEASE" with mode-compile.el version: 2.29 (Last modified: 2006/12/01 13:52:47)
The command line generated by mode-compile.el to compile (run) my buffer a.rb is this:
c:/ruby/bin\ruby.exe -w c:/Documents and Settings/William/My Documents/src/a.rb
Which generates this error:
c:/ruby/bin\ruby.exe: No such file or directory -- c:/Documents (LoadError)
This works just fine:
c:/ruby/bin\ruby.exe -w "c:/Documents and Settings/William/My Documents/src/a.rb"
As a work-around, I can just move my directory tree so that the path has no embedded blanks. Looking at the code in mode-compile.el, it APPEARS that a function exists already to add the quotes, however, as I am NOT proficient in emacs-lisp, perhaps this actually does something entirely different (like just appending a nearly-empty par of double quote marks):
(if to-compile-fname
(if mc--build-op-args
(mc--build-output-args to-compile-fname)
(concat " " to-compile-fname)
)
" "))))
mode-compile.el comes from here:
http://perso.tls.cena.fr/boubaker/distrib/mode-compile.el
Thanks in advance!
William
I don't have time to test this really, but it appears to me that the function mc--shell-compile needs to be updated. The filename of the buffer is extracted by the following lines:
(shfile (or mc--remote-pathname (buffer-file-name)
(error "Compilation abort: Buffer %s has no filename"
(buffer-name))))
the fix should be to quote the buffer-file-name:
(shfile (or mc--remote-pathname (shell-quote-argument buffer-file-name)
(error "Compilation abort: Buffer %s has no filename"
(buffer-name))))
Can you have a try and report, please?
Cheers,
Daniel

Resources