veripool / verilog-mode

Verilog-Mode for Emacs with Indentation, Hightlighting and AUTOs. Master repository for pushing to GNU, verilog.com and veripool.org.
http://veripool.org/verilog-mode
GNU General Public License v3.0
247 stars 90 forks source link

Enhance hide show #1708

Closed my2817 closed 3 years ago

my2817 commented 3 years ago

With following settings, it's able to indent or hideshow code block by tap key TAB

(defun my-hideshowvis-fringe ()
  (interactive )
  (end-of-line)
  (if (save-excursion
        (end-of-line 1)
        (or (hs-already-hidden-p)
            (progn
              (forward-char 1)
              (hs-already-hidden-p))))
      (hs-show-block)
    (hs-hide-block)
    ;; (beginning-of-line)
    ))
(defun my-verilog-readonly ()
  "set buffer to read-only if Engineer field of header not equal to `uer-login-name' "
  (interactive)
  (save-excursion
    (goto-line 1)
    (search-forward "Engineer    : " nil t)
    (forward-char)
    (let ((system-user (user-login-name))
          file-author  (symbol-at-point))
      (and (not (string= system-user file-author))
           (require 'git-timemachine)
           (not git-timemachine-mode)
           (read-only-mode 1)
           )
      )))

(defun my-verilog-indent/hs ()
  "work around `electric-verilog-tab', indent or hide/show fring.
If `buffer-read-only' is non-nil, execute `my-hideshowvis-fringe'.
If `electric-verilog-tab' don't change position, execute `my-hideshowvis-fringe'.
"
  (interactive)
  (if (or buffer-read-only
          (let* ((old-position (point))
                 (new-position (progn (electric-verilog-tab)
                                      (point))))
            (= old-position new-position))
          )
      (my-hideshowvis-fringe)))

  (define-key verilog-mode-map "\t" 'my-verilog-indent/hs)
wsnyder commented 3 years ago

Thanks for the contribution.

  1. I'm not sure why the patch has any test changes, perhaps that's for something different and they can be removed?
  2. I believe putting endif/ifdef in the regexps as you've done will mess up when the ifdefs are around something unusual, e.g.
   `ifdef A
       clocking a;
   `else
       clocking b;
   `endif
   endclocking

Thus my inclination would be to leave this patch for reference for others rather than merge it.

my2817 commented 3 years ago

Thanks for the contribution.

1. I'm not sure why the patch has any test changes, perhaps that's for something different and they can be removed?

2. I believe putting endif/ifdef in the regexps as you've done will mess up when the ifdefs are around something unusual, e.g.
   `ifdef A
       clocking a;
   `else
       clocking b;
   `endif
   endclocking

Thus my inclination would be to leave this patch for reference for others rather than merge it.

Judging from the test results these days(same as what you mentioned ), this path can't work on some unusual. And I changed some test case but not well thought out. I agree that don't merge this.

At last, thanks for your work at this awesome tool. It opened the world of emacs to me!

wsnyder commented 3 years ago

Closing as not merging - see above - again thanks for filing this.