emacs-pretest-bug
[Top][All Lists]
Advanced

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

php-bug, multi- and single-line comment switches


From: Andreas Roehler
Subject: php-bug, multi- and single-line comment switches
Date: Thu, 09 Mar 2006 20:34:33 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050921

Hi,
answering at two letters:

See three items to do with commenting:

- html-mode comments PHP-Code wrongly as html
- lacking multiline/singleline comment switches
- comment-dwim has no line orientation, requires an active region

> AFAIS there is a bug in newcomment.el
> > Missing routine to check if we are inside a
> > php-construct, where we need php-comment instead of
> > html-comment.

> Not clear where is the bug: you're presumably editing this buffer using
> html-mode, which tells Emacs that what you're writing is HTML text,
...
>
> Please try to use one of the various multi-mode packages (mmm-mode for
> example)

There are always ways with Emacs to do it, sure. My
suggestion is to enable it right out of the box. People
will use html-mode, insert php-code ... and lose time.

Why not implement a routine as already sent,
which checks, if being inside a php-construct?

(defun if-inside-php ()
  " "
  (interactive)
  (let (
        ;; (case-fold-search t)
        (php-start-pos
         (save-excursion
           (if (re-search-backward "<\\?php\\|<\\?PHP\\|<\\?\\|<%" nil t 1)
               (match-beginning 0)
             (point-min))))
        (html-js-start-pos
         (save-excursion
           (if (re-search-backward "<!--" nil t 1)
               (match-beginning 0)
             (point-min))))
        (php-end-pos
         (save-excursion
           (if (re-search-forward "\\?>\\|%>" nil t 1)
               (match-end 0)
             (point-max))))
        (html-js-end-pos
         (save-excursion
           (if (re-search-forward "-->" nil t 1)
               (match-end 0)
             (point-max)))))
    (if
        (and (> php-start-pos html-js-start-pos)
             (< php-end-pos html-js-end-pos))
        (setq inside-php t)
      (setq inside-php nil))))

Afterswards html-mode will select the right stuff - if
the vars are installed to that purpose.

--------

If there is a feature in languages as common as C and C++

-  different ways to comment -

 /* Example code */ and  // Example code

Emacs should support that.

AFAIS cc-mode varlists need to be extended to that
purpose. Not really difficult. Would do that and send
the diffs.

> > Suggest to change the default from
region-transient-mark-mode-requiring to
> > an line-oriented behavior, which respects region per default if
> > transient-mark-mode is on.

> The default of what?  You mean you want to change
comment-region so that it also works when no region is
selected (and comments the current line instead)?

In that way: My suggestion is to make things as easy as
possible. If I'm on a line, struck by the idea to
comment it, why then care for transient-mark-mode and
active region stuff?

However, should I care for some reasons - because its just
the region in my mind -, this should be
taken. Below again my example of a line-oriented
comment/uncomment function. Just try it with an active
region and without. Also there is a reinsert
facility...



Andreas

PS.: If `(comment-normalize-vars)' is needed, I'm not sure, don't notice
a difference without that. Commented at the moment.

(defun ar-comment-uncomment (&optional arg)
  "Comments or uncomments a line according to state
before.
Calls `comment-region' (unless line is already commented, in which case
it calls `uncomment-region').
With key pressed, continues with next line.
Works on region if mark and transient-mark-mode are active.
With arg greater than 1 works on arg lines, neglecting
region.
With arg equal 1 copies, comments/uncomments
and reinserts line."
  (interactive "*P")
  ;; (comment-normalize-vars)
  (let ((arg (if arg (prefix-numeric-value arg) 0))
        (start (if (and mark-active transient-mark-mode)
                   (region-beginning)))
        (startline (count-lines 1 (point)))
        (end (if (and mark-active transient-mark-mode)
                 (region-end)))
        (endline (if (and mark-active transient-mark-mode)
                     (count-lines 1 (region-end))
                   (count-lines 1
                                (save-excursion
                                    (forward-line arg)
                                    (line-end-position)))))
        (line-to-comment-or-uncomment (buffer-substring-no-properties
(line-beginning-position) (line-end-position))))
    (cond ((eq 1 arg) ;; comment and reinsert
           (progn
             (comment-or-uncomment-region (line-beginning-position)
(line-end-position))
             (indent-according-to-mode)
             (end-of-line)
             (newline)
             (insert line-to-comment-or-uncomment)
             (indent-according-to-mode)))
          ((< 1 arg) ;; comment/uncomment as lines are given
           (while (<= 1 (prefix-numeric-value arg))
             (comment-or-uncomment-region (line-beginning-position)
(line-end-position))
             (indent-according-to-mode)
             (end-of-line)
             (forward-line 1)
             (indent-according-to-mode)
             (setq arg (1- arg))))
          ((and start end) ;; region is active
           (comment-or-uncomment-region start end)
           (indent-according-to-mode)
           (if (eobp)
               (progn (newline)
                      (indent-according-to-mode))
             (progn
               (forward-line 1)
               (indent-according-to-mode))))
          (t ;; just one line
           (progn (comment-or-uncomment-region (line-beginning-position)
(line-end-position))
                  (indent-according-to-mode)
                  (if (eobp)
                      (progn (newline)
                             (indent-according-to-mode))
                    (progn
                      (forward-line 1)
                      (indent-according-to-mode))))))))





reply via email to

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