1.1 Highlight Code
Attachments: highlight%20code.png ID: 98ca483b-70bd-4a8b-b1b9-d604672fb8f3
You can use highlighting tools to mark code with different colors like taking notes to distinguish code.
- I used Emacs package symbol-overlay or other similar highlighting packages.
2.1 Jump to definition of any code
There are some options to select:
- Use text searching tools directly, Emacs
- If you want advanced text searching, can use "
regexpsearch", Emacs has built-in support, and has some packages to help you, even can use PCRE (Perl regexp) in Emacs with package "
- In current buffer, you can use
Imenu, etc to jump.
- Or even open an class/functions definitions sidebar to have an overview of your code.
2.2 Jump to definition of thing-at-point
When code definition is not in the same window page area, you want to jump to definition.
You can use
xref.el (which is Emacs built-in support now). If you want to keep current
code viewing, you can create a function to accept universal prefix argument
[M-.] to open code definition in other window. If you don't
want to mess your windows up, you also can try Emacs new feature (from 26?) "child-frame".
There is an existing package called "posframe" can be helpful.
3 Figure out of Code by running it
Attachments: Edebug%20result%20at%20point.png ID: 6c961996-eff9-41fa-a420-9272520996af
Sometimes I can't understand the code by reading, then I try to run code with debugger/tracer.
For example, Elisp code, Emacs has built-in tool
Because Edebug show stop point result in echo-area (minibuffer). It is not convinient for me. I want it displayed at point.
Here is my trick after I dive into Edebug source code:
(defun my:edebug-previous-result () "Print the previous result." (interactive) ;; (pos-tip-show edebug-previous-result 'popup-face) ; slow (popup-tip edebug-previous-result :truncate t :height 20 :width 45 :nostrip t :margin 1 :nowait nil) ) (advice-add 'edebug-previous-result :override #'my:edebug-previous-result)
Tip: Sometimes edebug will auto scroll down, when stop point moves to bottom of window,
the result popup is truncated, you can use C-l (
to recenter window. Then redisplay result popup with
More programming languages has more relative tools. I will not list them one by one at here. Just give out some examples that wish can inspire you. That's all.
4 TODO Will add more tricks here in future
Record to My Org node "Read Code" too.