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

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

Re: comment-dwim bug


From: Dan Nicolaescu
Subject: Re: comment-dwim bug
Date: Mon, 30 Aug 2004 10:32:03 -0700

Richard Stallman <address@hidden> writes:

  > The person who used to work on that code is Stefan,
  > but he is busy nowadays and we are waiting for him to fix
  > several bugs.  Could you possibly investigate and fix this one?

Sure. 

We start with this text in a buffer:

;; (defvar ediff-force-faces nil  
;; "If t, Ediff will think that it is running on a display that supports faces.
;; This is provided as a temporary relief for users of face-capable displays
;; that Ediff doesn't know about.")

Then after doing M-x transient-mark-mode RET C-x h M-x comment-dwim RET

comment-dwim calls comment-or-uncomment-region which calls
uncomment-region. 

uncomment-region uncomments the first 2 lines, so this is in the buffer:

(defvar ediff-force-faces nil  
"If t, Ediff will think that it is running on a display that supports faces.
;; This is provided as a temporary relief for users of face-capable displays
;; that Ediff doesn't know about.")

the point is before the first ;;

Then uncomment-region calls (comment-search-forward end t)
where end is the region end.
This should move the point right before 'This', but it moves it 2
lines down. 

This happens because of this statement in comment-search-forward: 
          (if comment-use-global-state (syntax-ppss pt))

(this is code that is not present in emacs-21.3)
It can be seen that the commented lines appear to be inside the
docstring... 
comment-use-global-state is t

So the solution would be to bind `comment-use-global-state' to nil in
comment-dwim because uncomment-region works one line at a time, so as
shown above it can appear that some commented lines are inside a
string.... A patch is attached, please apply if it's OK. 

Maybe the same thing is needed for other functions that call
uncomment-region... 

Disclaimer: this is the first time I looked at this code...

2004-08-30  Dan Nicolaescu  <address@hidden>

        * newcomment.el (comment-dwim): Bind comment-use-global-state to
        nil. 

*** newcomment.el       20 Aug 2004 14:28:33 -0700      1.77
--- newcomment.el       30 Aug 2004 10:25:54 -0700      
***************
*** 1055,1078 ****
  Else, call `comment-indent'."
    (interactive "*P")
    (comment-normalize-vars)
!   (if (and mark-active transient-mark-mode)
!       (comment-or-uncomment-region (region-beginning) (region-end) arg)
!     (if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$")))
!       ;; FIXME: If there's no comment to kill on this line and ARG is
!       ;; specified, calling comment-kill is not very clever.
!       (if arg (comment-kill (and (integerp arg) arg)) (comment-indent))
!       (let ((add (if arg (prefix-numeric-value arg)
!                  (if (= (length comment-start) 1) comment-add 0))))
!       ;; Some modes insist on keeping column 0 comment in column 0
!       ;; so we need to move away from it before inserting the comment.
!       (indent-according-to-mode)
!       (insert (comment-padright comment-start add))
!       (save-excursion
!         (unless (string= "" comment-end)
!           (insert (comment-padleft comment-end add)))
!         (indent-according-to-mode))))))
! 
! (defcustom comment-auto-fill-only-comments nil
    "Non-nil means to only auto-fill inside comments.
  This has no effect in modes that do not define a comment syntax."
    :type 'boolean)
--- 1055,1082 ----
  Else, call `comment-indent'."
    (interactive "*P")
    (comment-normalize-vars)
!   ;; Bind `comment-use-global-state' to nil. While uncommenting a
!   ;; (which works a line at a time) region a comment can appear to be
!   ;; included in a mult-line string, but it is actually not.
!   (let ((comment-use-global-state nil))
!     (if (and mark-active transient-mark-mode)
!       (comment-or-uncomment-region (region-beginning) (region-end) arg)
!       (if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$")))
!         ;; FIXME: If there's no comment to kill on this line and ARG is
!         ;; specified, calling comment-kill is not very clever.
!         (if arg (comment-kill (and (integerp arg) arg)) (comment-indent))
!       (let ((add (if arg (prefix-numeric-value arg)
!                    (if (= (length comment-start) 1) comment-add 0))))
!         ;; Some modes insist on keeping column 0 comment in column 0
!         ;; so we need to move away from it before inserting the comment.
!         (indent-according-to-mode)
!         (insert (comment-padright comment-start add))
!         (save-excursion
!           (unless (string= "" comment-end)
!             (insert (comment-padleft comment-end add)))
!           (indent-according-to-mode)))))))
!   
!   (defcustom comment-auto-fill-only-comments nil
    "Non-nil means to only auto-fill inside comments.
  This has no effect in modes that do not define a comment syntax."
    :type 'boolean)







reply via email to

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