I used https://opensource.apple.com/source/lldb/lldb-69/utils/emacs/gud.el and https://github.com/ptrv/emacs.d/blob/master/site-lisp/gud-lldb.el
, and with emacs 24.3 and lldb in LLVM 3.9.1. It can stop at breakpoint, and display the cursor at the correct source file in a separate emacs window. But 'up'/'down' command in lldb shows the new source code only in the lldb emacs window. There is no a new emacs window showing the new source code.
's'/'fin' can show the correct code in different windows.
Is this expected?
I had better luck with https://github.com/ptrv/emacs.d/blob/master/site-lisp/gud-lldb.el in emacs 25.3.1. It also has the advantage that it doesn't try to patch gud.el. I is a more self contained solution. It also failed to move the cursor when moving up and down the stack frames but with this change it works:
*** gud-lldb.el.orig 2017-12-11 17:22:08.000000000 -0700
--- gud-lldb.el 2017-11-18 11:52:55.000000000 -0700
***************
*** 64,73 ****
;; * thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread
(string-match " at \\([^:\n]*\\):\\([0-9]*\\), stop reason = .*\n"
gud-marker-acc start)
! ;; (lldb) frame select -r 1
! ;; frame #1: 0x0000000100000e09 a.out`main + 25 at main.c:44
! (string-match "^[ ]*frame.* at \\([^:\n]*\\):\\([0-9]*\\)\n"
! gud-marker-acc start))
;(message "gud-marker-acc matches our pattern....")
(setq gud-last-frame
(cons (match-string 1 gud-marker-acc)
--- 70,79 ----
;; * thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread
(string-match " at \\([^:\n]*\\):\\([0-9]*\\), stop reason = .*\n"
gud-marker-acc start)
! ;; cherry
! ;; (lldb) frame #1: 0x000000010013e29a sta`sta::PathEnumFaninVisitor::visitFromToPath(sta::Pin const*, sta::Vertex*, sta::TransRiseFall const*, sta::Tag*, sta::PathVertex*, sta::Edge*, sta::TimingArc*, float, sta::Vertex*, sta::TransRiseFall const*, sta::Tag*, float&, sta::MinMax const*, sta::PathAnalysisPt const*) + 986 at /Users/foobar/File.cc:348
! (string-match "^.*frame.* at \\([^:\n]*\\):\\([0-9]*\\)\n"
! gud-marker-acc start))
;(message "gud-marker-acc matches our pattern....")
(setq gud-last-frame
(cons (match-string 1 gud-marker-acc)
jjcherry56, your change works. And, since you found it, I upvoted the previous answer to 0, from -1.
So, I looked at that delta, and ended up making a small change explicitly.
In particular, I changed the part of the pattern:
string-match "^[ ]*frame
to
string-match "^.*frame
And it worked!
Admittedly, the "before" pattern (from jjcherry56's delta) in gud-lldb.el, ^[ ]*frame), was closer than ^frame (which was in the original modified gud.el, and which didn't work at all, and that file overwrote other language debuggers).
So, the modified pattern now takes anything from the beginning of the line to frame, rather than just zero or more blanks. Much closer, if not, in fact, "there" (not even thinking about boundary conditions of multiple instance of "frame" on the line, and other deep testing :-).
jjcherry56, I suspect that someone's original downvote was because of the reference to the asker as "nube", and the absence of a specific summary of the explanation (it was certainly not me, and it was perhaps excessive, especially considering that your change has merit, but I can understand the reaction).
The gud-lldb.el is definitely better for the reason(s) you stated, and your fix now allows me (and others (you too, Joe C)) to move forward in the quest to (continue to be able to) debug sanely using emacs/gud on the Mac.
PS I've tried everything to use gdb (I envy all those folks for whom it worked), no luck, so this is a saver. Hey, I can actually set a breakpoint at depth, and M-x lldb stops there, and gives me the arrow in the buffer (which it will pop up)!
Related
I am using Dr Racket for racket programming. I am a newbie.
I have run into this problem where when I type anything on the REPL, lets say:
> (define a 7)
The cursor never returns.
If I define this in the editor
(define a 7)
And in the REPL I do
> a
The cursor never returns.
I do have #lang racket at the very top in the editor window.
It was working just fine for some time and then it suddenly stopped working.
Can you help?
It is an old bug that sometimes appears on Ubuntu, no one has yet figured out why.
On relevant problem report: http://bugs.racket-lang.org/query/?cmd=view&pr=12640
I find it much less frequent these days though.
Meanwhile, I've found that if the pointer doesn't return, you can type other things like 'a or 1.1 followed by Enter, and it should evaluate both expressions at once and return the pointer. Note that the particular case that you give does not occur on my machine.
(define a 7)
should not be printing anything. It is merely binds a to be 7. Try typing a into REPL after and see what you get.
See Racket's documentation on define for further info.
Say you have a tree of the following form:
* Top
** Item A
*** Lower
** Item B
** Item C
What I would like to do is to be able to make a region containing Item A and Item B, and have a command run to change it into this:
* Top
**
*** Item A
**** Lower
*** Item B
** Item C
With the cursor at the blank item. I am wondering if something similar is already written into org-mode. If not, I can write it myself, but in that case I am wondering how I should loop through the lines in my region to shift them, avoiding items which are on a lower level than my starting one.
A naive first try
Starting with the outline
* Top
** Item A
*** Lower
** Item B
** Item C
If I place my cursor after Top and press Alt + Return (org-insert-heading) followed by Alt + Shift + right (org-demote-subtree) I get the structure
* Top
**
*** Item A
**** Lower
*** Item B
*** Item C
Unfortunately this demotes Item C, which you don't seem to want. However, you can just navigate to this item and press Alt + Shift + left. However, I imagine that this is a simplified example and want a more powerful method which doesn't involve moving around the file too much. Can we do better?
Transient mark mode
Reading through structure editing in the Org mode manual I found the note
When there is an active region (Transient Mark mode), promotion and demotion work on all headlines in the region. To select a region of headlines, it is best to place both point and mark at the beginning of a line, mark at the beginning of the first headline, and point at the line just after the last headline to change.
So perhaps this gives us a way forward. However, I haven't been able to do anything sensible with this information. Hopefully someone else can step and and show us how it is done.
Narrowing to a region
One other way we can move more is to "narrow" the buffer to only the region we want to work on.
Select the lines * Top, ** Item B in full and everything in between (with your mouse or by, for example, using Ctrl + Space and Ctrl + c + Ctrl + n (outline-next-visible-heading) a few times). We can now focus our attention on only this highlighted (or marked) region by "narrowing" the buffer to only this region, to the exclusion of all other text in the buffer (we won't delete the text, even though it will look that way, we'll just hide it for a bit. We narrow to the region by using Ctrl + x + n + n (narrow-to-region) (note the helpful message that appears if you haven't explicitly enabled this feature). We can always get back to the full buffer by using Ctrl + x + n + w (widen).
In our narrowed buffer we can now only see:
* Top
** Item A
*** Lower
** Item B
If we now repeat the steps from our naive try (see above) and then returning to the full (widened) buffer we see that we have the outline:
* Top
**
*** Item A
**** Lower
*** Item B
** Item C
which is the final result we were after! My apologise if this is an unnecessarily long answer. I learnt a lot researching it and wanted to document it all here.
Based off Chris's answer, I came up with the following code:
(defun org-file-region (start end)
"Moves the lines in region to be underneath a new header"
(interactive "r")
(extend-region-to-lines start end)
(narrow-to-region (save-excursion (goto-char start)
(line-beginning-position))
(save-excursion (goto-char end)
(line-end-position)))
(org-do-demote)
(org-insert-heading)
(setq mark-active nil)
(org-do-promote)
(setq mark-active t)
(widen))
Note that only org-do-demote will operate on the region; the other demotion functions do not.
This has got to be a stupid simple question, but I haven't been able to find an answer despite searching Google multiple times in multiple ways, and digging through the Calc documentation.
GIVEN an instance of Emacs, with Calc running, and having performed multiple calculations including storing variables and equations, some of which may have come from the "~/.emacs.d/calc.el" file,
HOW do you return Calc to a pristine state without restarting Emacs?
Pristine: Nothing on the stack. Nothing in the trail. No stored variables or equations. Etc.
M-x calc-reset, which is also bound to C-x * 0, is what you need. From the info manual:
The C-x * 0' command ('calc-reset'; that's 'C-x *' followed by a
zero) resets the Calculator to its initial state. This clears the
stack, resets all the modes to their initial values (the values that
were saved withm m' (calc-save-modes')), clears the caches (*note
Caches::), and so on. (It does _not_ erase the values of any
variables.) With an argument of 0, Calc will be reset to its default
state; namely, the modes will be given their default values. With a
positive prefix argument,C-x * 0' preserves the contents of the stack
but resets everything else to its initial state; with a negative prefix
argument, `C-x * 0' preserves the contents of the stack but resets
everything else to its default state.
EDIT: Oops. Even that doesn't clear variables. I'm not sure if there is a straightforward way to get all the way back to pristine :(
EDIT 2: It looks like Calc stores all variables, including 'built-ins' like pi and e, as global variables with the prefix 'var-'. As far as I can tell, it doesn't keep track of which variables were set by the mode (like pi), and which were set by users. Furthermore, the default user variables are stored as var-q0, var-q1 etc. So in order to clear out all the variables, you'd need to compile a list of variables and states present at startup, erase everything not in that list, and then restore the original values of the variables in that list. That's certainly possible, but a little tedious.
Edit 3: Here's my attempt. I took another look at calc-mode, and at start up it defines the variables I've added to my-calc-builtin-vars below. The second line will remove all variables in Emacs that start with the prefix 'var-' and are not in this list. This will include any variables defined by you, or in another package. So let's hope no-one else uses the prefix 'var-'. And it will not reset the value of the built-in variables, so if you have redefined pi to 3, it will remain 3.
(setq my-calc-builtin-vars
'("var-nan" "var-uinf" "var-sym" "var-lines" "var-Modes"
"var-EvalRules" "var-inf" "var-phi" "var-pi" "var-gamma" "var-π"
"var-φ" "var-γ" "var-spec" "var-e" "var-i"))
(defun really-reset-calc ()
(interactive)
(calc-reset nil)
(mapc #'(lambda (el) (unintern el))
(remove nil (mapcar
#'(lambda (el) (unless (member el my-calc-builtin-vars) el))
(all-completions "var-" obarray)))))
UPDATE: August 6, 2016
Current built-in vars list:
(setq my-calc-builtin-vars
'("var-CommuteRules" "var-Decls" "var-DistribRules" "var-EvalRules"
"var-FactorRules" "var-FitRules" "var-Holidays" "var-IntegAfterRules"
"var-IntegLimit" "var-InvertRules" "var-JumpRules" "var-MergeRules"
"var-Modes" "var-NegateRules" "var-e" "var-gamma" "var-i" "var-phi"
"var-pi" "var-γ" "var-π" "var-φ"))
M-# 0
That should be all you need to do.
Emacs version I am using:
GNU Emacs 22.2.1 (i386-redhat-linux-gnu, GTK+ Version 2.12.9)
Invoking gdb from emacs breaks the horizontal scrolling in emacs windows. I invoke gdb by entering M-x gdb and then accept the default (only adding name of my binary at the end, e.g.):
gdb --annotate=3 unittest
At some point after the debugger is invoked (not immediately), the automatic horizontal scrolling no longer works.
By automatic horizontal scrolling I mean that the expected behaviour is: follow the cursor, shifting the viewport left or right when necessary. For example: when the cursor is positioned at the end of a long line (say column 200) the viewing area of the window is moved to the right, such that column 200 is visible. If I then press 'Home' and the cursor jumps to beginning of line - the window also follows it and I can see the left-most column of the buffer.
Pasting my entire .emacs file here is probably a bad idea so I just searched for entries related to hscroll:
(custom-set-variables
'(column-number-mode t)
'(cua-mode t nil (cua-base))
'(hscroll-global-mode t nil (hscroll))
'(hscroll-margin 5)
'(hscroll-mode-name " ")
'(hscroll-snap-threshold 30)
'(indent-tabs-mode nil)
...
... but I can attach it here or email it if anyone thinks it is needed...
Hope someone knows how to fix this as coz it's a real pain - every time I use the debugger I need to restart emacs... I am pretty sure this problem was not present in version 20....
What does this do?
(add-hook 'compilation-mode-hook #'my-setup-compile-mode)
...and is it different than
(add-hook 'compilation-mode-hook 'my-setup-compile-mode)
There is no difference:
(eq 'my-add #'my-add)
yields t
The # can be used in front of a lambda expression indicating to the byte-compiler that the following expression can be byte compiled, see the docs for Anonymous Functions. But there's nothing to compile in the case of a symbol.
In general, it is used in the printed representation along with the left angle bracket (<) to indicate that the object printed is a description (but cannot be read). For example:
#<buffer foo.txt>
It is also used in constructs by the reader to represent circular structures. See the docs for Read Syntax for Circular Objects.
And then you have its use for denoting the base for integers, e.g. #x2c -> 44.
Plus more I'm sure.
The should-be-comprehensive list can be found at the top of the Emacs lisp reference index.
Edit: Or even more conveniently, from within Emacs itself:
M-x info RET (open the info browser)
d m elisp RET (open the elisp manual)
I # RET (list the entries for # in the index)
I found this question while searching for what the hash meant in something I found while hacking mode-line-format:
#("-%-" 0 3
(help-echo "Display as tooltip when mouse hovers or with display-local-help."))
which is a format used for text properties in strings where:
"-%-", text to be propertized: one dash and a %-construct that results in "dashes sufficient to fill the remainder of the mode line", resulting in the famous Emacs ------.
0, the first character upon which the text properties apply.
3, the last character upon which the text properties apply, i.e. the entire "-%-".
(help-echo "..."), a property and a string as its argument.
This can be created with the propertize function:
(propertize "Hover over me!" 'help-echo '"congratulations!")
would be the same as #("Hover over me!" 0 14 (help-echo "Congratulations!")):
If you're using font lock mode, using the buffer-substring command might produce something like this:
(buffer-substring 1 28) ; First 27 characters in the current buffer
⇒ #(";; This buffer is for notes"
0 3
(fontified t face font-lock-comment-delimiter-face)
3 27
(fontified t face font-lock-comment-face))
So you could create something like: