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

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

Problem Undoing Text Properties In Gnu Emacs 24, Is this a bug?


From: gtr289
Subject: Problem Undoing Text Properties In Gnu Emacs 24, Is this a bug?
Date: Fri, 12 Dec 2014 14:02:56 -0800 (PST)
User-agent: G2/1.0

Hello All,

I'm seeing a problem in Gnu Emacs 24.3.1 with undoing some text properties from 
some lisp code I wrote years ago as a light-weight C/C++ syntax highlighter 
that grays out C comments.  I never had a problem with Gnu Emacs 19, 20, 21 
versions. I've tested this in Gnu Emacs 21.2.1 . 

I work under Redhat 5 and also Cygwin and the problem exists in both. For some 
reason, after turning on rear-nonsticky the undo ring breaks. 

 To illustrate the problem I've included a skimmed down .el file that shows the 
basis of how it functions. 

Put it as test.el in $HOME directory and run:

"emacs -l ~/test.el"

Set a buffer in c++-mode and type some junk after a start comment BUT DON'T 
CLOSE THE COMMENT:

---->  /* wejhjhjkr hjw hwre

I used "red" for the comment color..

Now start hitting undo (f12) until all is gone and everything works fine.

Now, in c++-mode do it again and CLOSE THE COMMENT AND PUT SOME JUNK AROUND 
BOTH SIDES

--->  eqwe eqweqwe eqwqe    /* rrwrwr ewr rwrwe  */  ewqeq eqeqeqw eqwe

Start undoing with f12 key. It may not bug the first time but after a few 
attempts the undo ring will get stuck..  Try it multiple times..


Is this a bug ?  Why does it work in Emacs 21 ?   Is there a fix for this ?  Or 
a remedy ?

Any help is greatly appreciated..

Joe


Below is the example code:


;;;;;;;;;;;;;;;;;;;;;;;;;;
; Disable font-lock-mode ;
;;;;;;;;;;;;;;;;;;;;;;;;;;

(set-variable 'global-font-lock-mode  nil) 
(global-font-lock-mode 0)

;;;;;;;;;;;;;;;;;
; f12 is undo.. ;
;;;;;;;;;;;;;;;;;

(global-unset-key [f12] )
(global-set-key   [f12] 'undo)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Functions for setting text properties (maintain modify status) ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun jk-set-text-properties (p1 p2 state)
    (interactive)
    (let ( (modflag (buffer-modified-p)) )
       (set-text-properties p1 p2 state)
       (if (not modflag)
           (set-buffer-modified-p nil))))

(defun jk-add-text-properties (p1 p2 prop) 
    (interactive)
    (let ( (modflag (buffer-modified-p)) )
       (add-text-properties p1 p2 prop)
       (if (not modflag)
           (set-buffer-modified-p nil))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;  do-syntax looks for c+ comments --> /* ... */   ;
1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun do-syntax ()    
  (interactive)
  (let ()
    (cond
      (  (and (>= (point) 3)                          
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
             (equal (char-after (- (point) 2)) ?/ )       ;; we just type a 
start of comment -->  /*   ;
             (equal (char-after (- (point) 1)) ?* ) )     
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
         
             (setq savepos (point))
             (save-excursion                                                    
                ;;;;;;;;;;;;;;;;; 
                    (jk-set-text-properties (- savepos 2)  savepos '(face 
'(:foreground  "red") ))  ;; turn on red  ;
         )                                                                      
            ;;;;;;;;;;;;;;;;;
      )

      (  (and (> (point) 2)                        
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
             (equal (char-after (- (point) 2)) ?* )    ;; we just typed close 
of comment -->  */  ;
             (equal (char-after (- (point) 1)) ?/ ) )  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
           
             (setq savepos (point))
             (save-excursion                                                    
   ;;;;;;;;;;;;;;;;;;;;;;
               (jk-add-text-properties  (-(point)1) (point) '(rear-nonsticky t 
))  ;; End the comment   ;
         )                                                                     
;;;;;;;;;;;;;;;;;;;;;;
      ) 
    )  ;; cond
  ) ;; let
  nil          
) ;; end do-syntax


(setq  post-command-hook  nil)

(add-hook 'post-command-hook
     (function 
       (lambda ()
         (do-syntax))))



reply via email to

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