foopang / mewde

Automatically exported from code.google.com/p/mewde
0 stars 0 forks source link

should not parse syntactically the line immediately after <?PHP as 'topmost-intro-cont' #4

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. open a new php file
2. type <?PHP, press <ENTER> or other keys which can produce a newline
3. type any legal statement at this line
4. `indent-according-to-mode' will treat this line as 'topmost-intro-cont'
(which should be 'topmost-intro') and as a result does not indent properly.

What is the expected output? What do you see instead?

treat syntactically the line after "<?PHP" as 'topmost-intro' instead of
'topmost-intro-cont'

What version of the product are you using? On what operating system?
1.4.1-nxhtml-mewde-additions on Emacs23@Linux with a cc-mode of version 5.31.6

Please provide any additional information below.
It seems that this can be solved by updating cc-mode to treat "<?PHP" as a
heuristic rule to give the line right after "<?PHP" as 'topmost-intro'. 
<pre>
;; CASE 5M: we are at a topmost continuation line
         (t
          (c-beginning-of-statement-1 (c-safe-position (point) paren-state))
          (let ((header-tag (buffer-substring-no-properties (- (point) 2)
(+ (point) 3))))
            (message header-tag)
            (if (or (string-equal header-tag "<?php")
                    (string-equal header-tag "<?PHP"))
                (progn
                  (c-add-syntax 'topmost-intro (c-point 'boi))
                  )
              (progn
                (when (c-major-mode-is 'objc-mode)
                  (setq placeholder (point))
                  (while (and (c-forward-objc-directive)
                              (< (point) indent-point))
                    (c-forward-syntactic-ws)
                    (setq placeholder (point)))
                  (goto-char placeholder))

                (c-add-syntax 'topmost-intro-cont (c-point 'boi)))
              )))
</pre>
But that's a rather ugly hack. Much better if it can be solved within php-mode.
Many Thanks!!

Original issue reported on code.google.com by sen.zh...@gmail.com on 2 Nov 2008 at 3:54

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
well, a not so nice hook can be used to fix the indentation, though the 
syntactic
type of the first line after "<?PHP" or "<?php" is still `topmost-intro-cont'. 
The
hook code is below:

(defun php-mode-fix-first-line-syntactic ()
  (interactive)
  (save-excursion
    (let ((paren-state (c-parse-state)))
      (c-beginning-of-statement-1 (c-safe-position (point) paren-state))
      (if (>= (- (point) 2) 1)
          (let ((header-tag (buffer-substring-no-properties (- (point) 2)
                                                            (+ (point) 3))))
            (message header-tag)
            (if (or (string-equal header-tag "<?php")
                    (string-equal header-tag "<?PHP"))
                (progn
                  (c-add-syntax 'topmost-intro (c-point 'boi))
                  (forward-char 4)
                  (indent-line-to 0)
                  )
              ))))))

(add-hook 'c-special-indent-hook 'php-mode-fix-first-line-syntactic)

Original comment by sen.zh...@gmail.com on 9 Nov 2008 at 10:34