Moonfire Games

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: csharp 0.7 and hide show minor mode problem  (Read 3812 times)

o3o

  • 100 point character
  • **
  • Status: 2
  • Posts: 4
    • View Profile
csharp 0.7 and hide show minor mode problem
« on: March 04, 2008, 12:54:23 AM »
Hi Dylan,
first of all many thanks for your great c#mode..then the problem :-)

I've emacs 22.1.1  for windows cc-mode 5.31.4 and csharp-mode.el 0.7.0.

My .emacs contains:

Code: [Select]
...
(add-hook 'csharp-mode-hook 'hs-minor-mode)

;; Patterns for defining blocks to hide/show:
(push '(csharp-mode
"\\(^\\s *#\\s *region\\b\\)\\|{"
"\\(^\\s *#\\s *endregion\\b\\)\\|}"
"/[*/]"
nil
hs-c-like-adjust-block-beginning)
     hs-special-modes-alist)



then, when I open a cs file :

Code: [Select]
Debugger entered--Lisp error: (error "C#/l Mode doesn't support Hideshow Minor Mode")
  signal(error ("C#/l Mode doesn't support Hideshow Minor Mode"))
  error("%s Mode doesn't support Hideshow Minor Mode" "C#/l")
  hs-grok-mode-type()
  hs-minor-mode()
  run-hooks(csharp-mode-hook)
  csharp-mode()
  set-auto-mode-0(csharp-mode nil)
  set-auto-mode()
  normal-mode(t)
  after-find-file(nil t)
  find-file-noselect-1(#<buffer Vars.cs> "~/CSharpArea/Microline/Noo/Vars.cs" nil nil "~/CSharpArea/Microline/Noo/Vars.cs" (14480 (45149 . 41649)))
  ad-Orig-find-file-noselect("c:/cygwin/home/dao/CSharpArea/Microline/Noo/Vars.cs" nil nil nil)
  (setq ad-return-value (ad-Orig-find-file-noselect filename nowarn rawfile wildcards))
  (let (ad-return-value) (setq ad-return-value (ad-Orig-find-file-noselect filename nowarn rawfile wildcards)) (folding-find-file-noselect) ad-return-value)
  find-file-noselect("c:/cygwin/home/dao/CSharpArea/Microline/Noo/Vars.cs" nil nil nil)
  find-file("c:/cygwin/home/dao/CSharpArea/Microline/Noo/Vars.cs")
  command-line-1(("Vars.cs"))
  command-line()
  normal-top-level()


Do you have some ideas?
thanks!



« Last Edit: March 04, 2008, 12:56:39 AM by o3o »
Logged

D. Moonfire

  • Divinity +N
  • 300 point character
  • *****
  • Status: 0
  • Posts: 309
    • View Profile
    • WWW
Re: csharp 0.7 and hide show minor mode problem
« Reply #1 on: March 05, 2008, 05:59:23 PM »
Hrm, I haven't gotten hide show mode to actually work with csharp-mode yet. I didn't think I still had bits and pieces in there, but look for the code that enables it and just comment it out for now.
Logged

o3o

  • 100 point character
  • **
  • Status: 2
  • Posts: 4
    • View Profile
Re: csharp 0.7 and hide show minor mode problem
« Reply #2 on: March 05, 2008, 11:51:43 PM »
thank for your reply,

...FYI I tested csharp mode in

"GNU Emacs 22.0.50.1 (i386-mingw-nt5.1.2600) of 2005-06-26"

and it works, but in

"GNU Emacs 22.1.1 (i386-mingw-nt5.1.2600) of 2007-06-02"
doesn't work
Logged

Cheeso

  • 100 point character
  • **
  • Status: 0
  • Posts: 5
    • View Profile
Re: csharp 0.7 and hide show minor mode problem
« Reply #3 on: April 12, 2008, 08:26:10 PM »
I did get hideshow.el to work with csharp-mode.el .  It required some custom elisp for a hs-forward-sexp-func specific to C#.  Basically it replaces the forward-sexp (a function to move forward one s-expression, think of it as one block), so that the forward steps can recognize region/endregion as well as curly braces.


Code: [Select]
(defun csharp-hs-forward-sexp (&optional arg)

  "I set hs-forward-sexp-func to this function.

I found this customization necessary to do the hide/show magic in C#
code, when dealing with region/endregion. This routine
goes forward one s-expression, whether it is defined by curly braces
or region/endregion. It handles nesting, too.

The forward-sexp method takes an arg which can be negative, which
indicates the move should be backward.  Therefore, to be fully
correct this function should also handle a negative arg. However,
the hideshow.el package never uses negative args to its
hs-forward-sexp-func, so it doesn't matter that this function does not
do negative numbers.

The arg can also be greater than 1, which means go forward
multiple times. This function doesn't handle that EITHER.  But
again, I haven't see that as a problem."

  (message "csharp-hs-forward-sexp, (arg %d) (point %d)..."
           (if (numberp arg) arg -1)
           (point))
 
  (let ((nestlevel 0)
        (mark1 (point))
        (done nil)
        )
   
    (if (and arg (< arg 0))
        (message "negative arg (%d) is not supported..." arg)

      ;; else, we have a positive argument, hence move forward.
      ;; simple case is just move forward one brace
      (if (looking-at "{")
          (forward-sexp arg)
       
        ; The more complex case is dealing with a "region/endregion" block.
        ; We have to deal with nested regions!
        (and
         (while (not done)
           (re-search-forward "^[ \\t]*#[ \\t]*\\(region\\|endregion\\)\\b"
                              (point-max) 'move)
           (cond
           
            ((eobp))                    ; do nothing if at end of buffer
           
            ((and
              (match-beginning 1)
              ;; if the match is longer than 6 chars, we know it is "endregion"
              (if (> (- (match-end 1) (match-beginning 1)) 6)
                  (setq nestlevel (1- nestlevel))
                (setq nestlevel (1+ nestlevel))
                )
              )))

           (setq done (not (and (> nestlevel 0) (not (eobp)))))
           
           )                            ; while
                       
         (if (= nest 0)
             (goto-char (match-end 2)))

         )
        )
      )
    )
  )

Drop that in your .emacs file, and then, add this to initialize hideshow:

Code: [Select]
(unless (assoc 'csharp-mode hs-special-modes-alist)
          (push '(csharp-mode
                  ; "\\(^\\s*#\\s*region\\b\\)\\|{"      ; regexp for start block DID NOT WORK
                  "\\(^[ \\t]*#[ \\t]*region\\b\\)\\|{"  ; regexp for start block
                 
                  ; "\\(^\\s*#\\s*endregion\\b\\)\\|}"   ; regexp for end block NO WORKY!
                  "\\(^[ \\t]*#[ \\t]*endregion\\b\\)\\|}"   ; regexp for end block
                 
                  "/[*/]"                                ; regexp for comment start
                 
                  csharp-hs-forward-sexp                 ; hs-forward-sexp-func
                  hs-c-like-adjust-block-beginning       ;c-like adjust (1 char)
                  ;csharp-hs-adjust-block-beginning      ;csharp adjust ?
                  )
                hs-special-modes-alist))


Put this in your csharp-mode-hook-function :
Code: [Select]
   (hs-minor-mode 1)
   (setq hs-isearch-open t)

This worked for me....

Logged
Pages: [1]   Go Up
« previous next »