help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: syntax parsing of non-contiguous regions


From: Andreas Röhler
Subject: Re: syntax parsing of non-contiguous regions
Date: Tue, 22 Sep 2009 07:42:57 +0200
User-agent: Thunderbird 2.0.0.19 (X11/20081227)

Alexander Katovsky wrote:
> I'm afraid I'm being a little slow understanding you're suggestion. 
> I've already defined comment-start and comment-end as '!' and '\n'
> respectively.  Also, I need all the syntax motion functions
> (forward-sexp, parse-partial-sexp et al) to treat the embedded code as
> a comment so that the embedded code does not disrupt syntax motion
> outside.  For example, suppose that my primary mode is for code
> consisting of named blocks with comments starting with '!' and ending
> with newline, and my embedded code is C.  Then we could have
>
> named-block  ! some comment
> {
>    %{
>        if(a != b){}
>    }%
> }
>
> Then the syntax motion functions would completely ignore the embedded
> code, just as it would a comment.  So if point is before the first
> opening brace then, no matter what's inside %{}%, forward-sexp would
> place point at the last closing brace.  And all the other syntax
> functions would just 'work' as well!
>
> I'd be very grateful if could explain in a little more detail exactly
> what the 'hide-or-ignore' functions that you suggest are and how they
> could be used to achieve this effect.
>
> Thanks,
> Alex
>
>
>
>

Below a test-implementation, where `forward-sexp' works  as expected:


(defun my-syntax-mode (arg &optional beg end)
  " "
  (interactive "p")
  (let ((beg (cond (beg beg)
                   ((region-active-p)
                    (region-beginning))
                   (t (point-min))))
        (end (cond (end end)
                   ((region-active-p)
                    (copy-marker (region-end)))
                   (t (point-max))))
        )
    (save-restriction
      (narrow-to-region beg end)
      (goto-char beg))
    (my-syntax-mode-intern arg beg end )
    (widen)))

(defun my-syntax-mode-intern (arg beg end)
 
  (let ((comment-start (concat comment-start "\\|%{"))
        (comment-end (concat comment-end"\|}%")))
    (forward-sexp)
      ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Mode was emacs-lisp, tested with

(defun foo (&optional beg end)
  " "
  (interactive "*")
  ;; (let ((beg (cond (beg beg)
  {
   %{
       if(a != b){}
   }%
}
           ((region-active-p)
            (region-beginning))
           (t (point-min))))
    (end (cond (end (copy-marker end))
           ((region-active-p)
            (copy-marker (region-end)))
           (t (copy-marker (point-max))))))
    (save-excursion
      (goto-char beg))
    (when (interactive-p) (message "%s %s" beg end))))

;;;;;;;;;;;;;;;;;;

Cursor starts behind   (interactive "*"), passes both comments.

So far

Andreas


 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]