Forums » Using AUTOs »
question about verilog-before-auto-hook and folding mode
Added by David Rogoff 6 months ago
Hi Wilson & others,
I've just gotten totally hooked on folding-mode (http://git.savannah.gnu.org/cgit/emacs-tiny-tools.git/tree/lisp/other/folding.el?h=devel). It's great for hiding most of my code so I can focus on the parts I'm working on.
However... ran into a snag when I went to update my autos. I have it set so folding-mode minor mode is automatically loaded for verilog fles:
(add-hook 'verilog-mode-hook '(lambda ()
(folding-mode)))
When verilog-auto runs on a folded file, it doesn't see the hidden code. No problem, I did this:
;; when running verilog-auto (c-c c-a), unfold first!!!!
(add-hook 'verilog-before-auto-hook '(lambda ()
(folding-open-buffer))
Problem is that that does what I want for the buffer where I ran verilog-auto. But it doesn't apply to any buffers that verilog-auto automatically loads for instantiated modules. Therefore, if I have ports hidden in those files, auto doesn't see them.
How can I configure it so the verilog=before-auto-hook applies?
Thanks!
Replies (9)
RE: question about verilog-before-auto-hook - Added by Wilson Snyder 6 months ago
Here's what it does for font lock mode on update...
(let (fontlocked (when (and (boundp 'font-lock-mode)
font-lock-mode)
(font-lock-mode 0)
t))
...
;; Unwind forms
(progn
;; Restore font-lock
(when fontlocked (font-lock-mode t))))))
The idea is that it turns it off to do the autos then makes things appear back to normal as they were before. Code like this is in several places so needs some refactoring. If you provide similar code for folding mode (note it must not cause errors if not active or installed) then I'll put it in.
RE: question about verilog-before-auto-hook - Added by David Rogoff 6 months ago
I'll try. I'm a real novice at elisp, but I'm good at copying and modifying other people's code!
RE: question about verilog-before-auto-hook - Added by Wilson Snyder 6 months ago
Really just need the function/code to see if it's on, turn it off, and turn it on in the same way as before turned off.
RE: question about verilog-before-auto-hook and folding mode - Added by David Rogoff 6 months ago
Wilson,
I've been messing around and this is what I've come up with:
It's crazy there's no specified way of setting/detecting minor modes!
Some ideas for detecting folding-mode
Check if folding-mode is in minor-mode-list If not, no problem(if (member 'folding-mode minor-mode-list)
If it is in there, see if the current buffer is in folding-mode I'm sure (or at least hope) there's a better way, but the only thing I've found is to check the mode line!
If(message "%s" (format-mode-line mode-line-format))contains "Fld" then the buffer could have hidden text so run
(folding-open-buffer)which unfolds everything so no text is hidden
If folding-mode is loaded, you could probably skip testing the mode line and just blindly run folding-open-buffer
Now, to be paranoid, if you were checking the buffer, you really need to check the value of folding-mode-menu-name in case someone was crazy enough to change it from the default of "Fld"
I hope this is enough to do the job!
Thanks again!
RE: question about verilog-before-auto-hook and folding mode - Added by David Rogoff 6 months ago
Upon further reflection, it doesn't seem reasonable for you to hack verilog-mode just for this particular issue since someone else could come along next week with a different buffer narrowing mode. I'd think you'd just want to add two new hooks, like verilog-before-auto-hook and verilog-auto-hook but that apply when reading in files for instantiated modules. Then I, and others, could do what we need.
RE: question about verilog-before-auto-hook and folding mode - Added by Wilson Snyder 5 months ago
Please try rev735 with verilog-after-save-font-hook and verilog-before-save-font-hook.
RE: question about verilog-before-auto-hook and folding mode - Added by David Rogoff 5 months ago
Wilson, I updated my verilog-mode (I was running one from April and found all sorts of other cool new features to try!) and set my init to this:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Code folding
;; always load folding-mode
(add-hook 'verilog-mode-hook '(lambda ()
(folding-mode)))
;; when running verilog-auto (c-c c-a), unfold first of ports of instantiated modules might not be seen!!!!
(add-hook 'verilog-before-auto-hook '(lambda ()
(folding-open-buffer)))
;; also for files automatically read in for AUTO expansion
(add-hook 'verilog-before-save-font-hook '(lambda ()
(folding-open-buffer)))
Unfortunately, it didn't make a difference. Files for instantiated modules were still folded and therefore the AUTOs were all messed up in the top-level module.
Any ideas?
Thanks!
RE: question about verilog-before-auto-hook and folding mode - Added by Wilson Snyder 5 months ago
Don't know. I see it removing the fontification correctly. You can try changing this
(unless verilog-save-font-mod-hooked
to (unless nil.
If that doesn't do it perhaps debug by add some (message "....") so you can see what's getting called.
RE: question about verilog-before-auto-hook and folding mode - Added by David Rogoff 5 months ago
You can try changing this
(unless verilog-save-font-mod-hooked
to
(unless nil.
That seems to work! I'll play with it some more in the next couple of days to make sure.
Thanks,
David
(1-9/9)
![[logo]](/img/veripool_small.png)