@@ -334,7 +334,6 @@ END : end changing point."
334334(defun line-reminder--remove-lines-out-range ()
335335 " Remove all the line in the list that are above the last/maxinum line \
336336or less than zero line in current buffer."
337- ; ; Remove line that are above last/max line in buffer.
338337 (let ((last-line-in-buffer (line-reminder--total-line))
339338 (check-lst (append line-reminder--change-lines line-reminder--saved-lines)))
340339 (dolist (line check-lst)
@@ -343,6 +342,24 @@ or less than zero line in current buffer."
343342 ; ; Remove line because we are deleting.
344343 (line-reminder--remove-line-from-change-line line)))))
345344
345+ (defun line-reminder--remove-lines (beg end comm-or-uncomm-p )
346+ " Remove lines from BEG to END depends on COMM-OR-UNCOMM-P."
347+ (let ((cur beg))
348+ ; ; Shift one more line when commenting/uncommenting.
349+ (when comm-or-uncomm-p (setq end (1+ end)))
350+ (while (< cur end)
351+ (if comm-or-uncomm-p
352+ (line-reminder--add-line-to-change-line cur)
353+ (line-reminder--remove-line-from-change-line cur))
354+ (setq cur (1+ cur)))))
355+
356+ (defun line-reminder--add-lines (beg end )
357+ " Add lines from BEG to END."
358+ (let ((cur beg))
359+ (while (<= cur end)
360+ (line-reminder--add-line-to-change-line cur)
361+ (setq cur (1+ cur)))))
362+
346363;;;### autoload
347364(defun line-reminder-transfer-to-saved-lines ()
348365 " Transfer the `change-lines' to `saved-lines' ."
@@ -399,10 +416,7 @@ or less than zero line in current buffer."
399416 (max-ln -1 )
400417 (adding-p (< (+ begin length ) end))
401418 ; ; Flag to check if currently commenting or uncommenting.
402- (comm-or-uncomm-p (and (not (= length 0 )) (not (= begin end))))
403- ; ; Generic variables for `addition` and `deletion`.
404- (current-linum -1 ) (record-last-linum -1 ) (reach-last-line-in-buffer -1 ))
405-
419+ (comm-or-uncomm-p (and (not (= length 0 )) (not (= begin end)))))
406420 (if (or adding-p comm-or-uncomm-p)
407421 (setq line-reminder--before-max-pt (+ line-reminder--before-max-pt (- end begin)))
408422 (setq line-reminder--before-max-pt (- line-reminder--before-max-pt length )))
@@ -433,34 +447,7 @@ or less than zero line in current buffer."
433447
434448 ; ; NOTE: Deletion..
435449 (unless adding-p
436- (progn
437- (setq current-linum begin-linum)
438- (setq record-last-linum begin-linum)
439- (setq reach-last-line-in-buffer nil ))
440-
441- (while (and (< current-linum end-linum)
442- ; ; Cannot be the same as last line in buffer.
443- (not reach-last-line-in-buffer))
444- ; ; To do the next line.
445- (forward-line 1 )
446- (setq current-linum (line-reminder--line-number-at-pos))
447-
448- ; ; Remove line because we are deleting.
449- (if comm-or-uncomm-p
450- (line-reminder--add-line-to-change-line current-linum)
451- (line-reminder--remove-line-from-change-line current-linum))
452-
453- ; ; NOTE: Check if we need to terminate this loop?
454- (when (or
455- ; ; Check if still the same as last line.
456- (= current-linum record-last-linum)
457- ; ; Check if current linum last line in buffer
458- (= current-linum (line-reminder--total-line)))
459- (setq reach-last-line-in-buffer t ))
460-
461- ; ; Update the last linum, make sure it won't do the same line twice.
462- (setq record-last-linum current-linum))
463-
450+ (line-reminder--remove-lines begin-linum end-linum comm-or-uncomm-p)
464451 (line-reminder--shift-all-lines starting-line delta-lines))
465452
466453 ; ; Just add the current line.
@@ -469,37 +456,7 @@ or less than zero line in current buffer."
469456 ; ; NOTE: Addition..
470457 (when adding-p
471458 (line-reminder--shift-all-lines starting-line delta-lines)
472-
473- ; ; Adding line. (After adding line/lines, we just need to loop
474- ; ; throught those lines and add it to `line-reminder--change-lines'
475- ; ; list.)
476- (progn
477- (setq current-linum begin-linum)
478- ; ; Record down the last current line number, to make sure that
479- ; ; we don't fall into infinite loop.
480- (setq record-last-linum begin-linum)
481- (setq reach-last-line-in-buffer nil ))
482-
483- (while (and (<= current-linum end-linum)
484- ; ; Cannot be the same as last line in buffer.
485- (not reach-last-line-in-buffer))
486- ; ; Push the current line to changes-line.
487- (line-reminder--add-line-to-change-line current-linum)
488-
489- ; ; To do the next line.
490- (forward-line 1 )
491- (setq current-linum (line-reminder--line-number-at-pos))
492-
493- ; ; NOTE: Check if we need to terminate this loop?
494- (when (or
495- ; ; Check if still the same as last line.
496- (= current-linum record-last-linum)
497- ; ; Check if current linum last line in buffer
498- (= current-linum (line-reminder--total-line)))
499- (setq reach-last-line-in-buffer t ))
500-
501- ; ; Update the last linum, make sure it won't do the same line twice.
502- (setq record-last-linum current-linum)))
459+ (line-reminder--add-lines begin-linum end-linum))
503460
504461 (delete-dups line-reminder--change-lines)
505462 (delete-dups line-reminder--saved-lines)
0 commit comments