bastibe / annotate.el

Annotate.el
Other
388 stars 20 forks source link

'annotate--remove-annotation-property' results in wrong behavior of comment-region #103

Closed seokbeomKim closed 3 years ago

seokbeomKim commented 3 years ago

Hi,

There is an issue that a function 'annotate--remove-annotation-property' results in 'args-out-of' error when doing comment-or-uncomment-region as following:

Back trace

Debugger entered--Lisp error: (args-out-of-range 866 867)
  remove-text-properties(866 867 (display nil))
  annotate--remove-annotation-property(831 834)
  comment-region-internal(830 863 "/* " " */" nil nil nil nil t)
  comment-region-default-1(830 863 nil)
  #f(compiled-function () #<bytecode 0x1ff6f5aab7dd>)()
  combine-change-calls-1(830 864 #f(compiled-function () #<bytecode 0x1ff6f5aab7dd>))
  comment-region-default(830 863 nil)
  comment-region(830 863 nil)
  comment-or-uncomment-region(830 863)
  crux-duplicate-and-comment-current-line-or-region(1)
  funcall-interactively(crux-duplicate-and-comment-current-line-or-region 1)
  #<subr call-interactively>(crux-duplicate-and-comment-current-line-or-region t nil)
  elmacro-record-command(#<subr call-interactively> crux-duplicate-and-comment-current-line-or-region nil nil)
  apply(elmacro-record-command #<subr call-interactively> (crux-duplicate-and-comment-current-line-or-region nil nil))
  call-interactively(crux-duplicate-and-comment-current-line-or-region nil nil)
  command-execute(crux-duplicate-and-comment-current-line-or-region)

Generating the problem

In the following code (c-mode), when I try 'comment-or-uncomment-region', its behavior is abnormal.

error:

static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
    struct uvc_xu_control_mapping *xmap)
{
    /* struct uvc_control_mapping *map;
    struct uvc_control_mapping *map;
    unsigned int size;

expect:

static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
    struct uvc_xu_control_mapping *xmap)
{
    /* struct uvc_control_mapping *map; */
    struct uvc_control_mapping *map;
    unsigned int size;

When I remove a bunch of code in the function as below, the issue has gone but I don't know whether this is okay.

(defun annotate--remove-annotation-property (begin end)
  "Cleans up annotation properties associated with a region."
  (when (> (buffer-size)
           0)
    (annotate-with-inhibit-modification-hooks
     ;; copy undo list
     (let ((saved-undo-list (copy-tree buffer-undo-list t)))
       ;; inhibit property removal to the undo list (and empty it too)
       (buffer-disable-undo)
       ;; restore undo list
       (setf buffer-undo-list saved-undo-list)
       (buffer-enable-undo)))))
cage2 commented 3 years ago

Hi @seokbeomKim !

Thank you for your detailed report!

So the problem arise when trying to comment the region that cover the line:

struct uvc_control_mapping *map;

and annotate-mode is course activated on the buffer with the text that needs to be commented. Right?

Now i wonder if this could be related someway to https://github.com/bastibe/annotate.el/issues/86. 🤔 I am going to reproduce the error on my machine and report the results here.

Bye and thanks a lot!
C.

cage2 commented 3 years ago

Hi @seokbeomKim !

I believe that the patch #106 should address your issue, May i ask you to check if it works?

Thanks a lot! C.