|
47 | 47 | (defvar-local auto-rename-tag--pre-command-actived nil |
48 | 48 | "Check if `pre-command-hook' called.") |
49 | 49 |
|
| 50 | +(defvar-local auto-rename-tag--after-action-active nil |
| 51 | + "Check if `after-action' is currently called.") |
| 52 | + |
50 | 53 | (defvar-local auto-rename-tag--record-prev-word "" |
51 | 54 | "Record down the word in `pre-command-hook'.") |
52 | 55 |
|
@@ -344,30 +347,33 @@ DIRECT can be either only 'backward and 'forward." |
344 | 347 |
|
345 | 348 | (defun auto-rename-tag--before-action () |
346 | 349 | "Before rename core action." |
347 | | - (setq auto-rename-tag--record-prev-word "") ; Reset record. |
348 | | - (setq auto-rename-tag--pre-command-actived nil) ; Reset flag. |
| 350 | + (unless auto-rename-tag--after-action-active |
| 351 | + (setq auto-rename-tag--record-prev-word "") ; Reset record. |
| 352 | + (setq auto-rename-tag--pre-command-actived nil) ; Reset flag. |
349 | 353 |
|
350 | | - (when (and (not undo-in-progress) |
351 | | - (auto-rename-tag--inside-tag-p) |
352 | | - (not (auto-rename-tag--self-tag-p))) |
353 | | - (save-excursion |
354 | | - ;; Set active flag. |
355 | | - (setq auto-rename-tag--pre-command-actived t) |
| 354 | + (when (and (not undo-in-progress) |
| 355 | + (auto-rename-tag--inside-tag-p) |
| 356 | + (not (auto-rename-tag--self-tag-p))) |
| 357 | + (save-excursion |
| 358 | + ;; Set active flag. |
| 359 | + (setq auto-rename-tag--pre-command-actived t) |
356 | 360 |
|
357 | | - (setq auto-rename-tag--record-prev-word (auto-rename-tag--get-tag-name-at-point)) |
| 361 | + (setq auto-rename-tag--record-prev-word (auto-rename-tag--get-tag-name-at-point)) |
358 | 362 |
|
359 | | - (when (string= auto-rename-tag--record-prev-word "/") |
360 | | - (setq auto-rename-tag--record-prev-word "")) |
| 363 | + (when (string= auto-rename-tag--record-prev-word "/") |
| 364 | + (setq auto-rename-tag--record-prev-word "")) |
361 | 365 |
|
362 | | - ;; Ensure `auto-rename-tag--record-prev-word' is something other than nil. |
363 | | - (unless auto-rename-tag--record-prev-word |
364 | | - (setq auto-rename-tag--record-prev-word ""))))) |
| 366 | + ;; Ensure `auto-rename-tag--record-prev-word' is something other than nil. |
| 367 | + (unless auto-rename-tag--record-prev-word |
| 368 | + (setq auto-rename-tag--record-prev-word "")))))) |
365 | 369 |
|
366 | 370 | (defun auto-rename-tag--after-action () |
367 | 371 | "After rename core action." |
368 | | - (when auto-rename-tag--pre-command-actived |
| 372 | + (when (and auto-rename-tag--pre-command-actived |
| 373 | + (not auto-rename-tag--after-action-active)) |
369 | 374 | (save-excursion |
370 | | - (let ((is-end-tag nil) |
| 375 | + (let ((auto-rename-tag--after-action-active t) |
| 376 | + (is-end-tag nil) |
371 | 377 | (current-word "") (pair-tag-word "")) |
372 | 378 | ;; Goto the first character inside the tag. |
373 | 379 | (auto-rename-tag--goto-the-start-of-tag-name) |
@@ -416,25 +422,18 @@ DIRECT can be either only 'backward and 'forward." |
416 | 422 | "Do stuff before buffer is changed." |
417 | 423 | (auto-rename-tag--before-action)) |
418 | 424 |
|
419 | | -(defun auto-rename-tag--after-change (&rest _args) |
420 | | - "Do stuff after buffer is changed." |
421 | | - (auto-rename-tag--after-action)) |
422 | | - |
423 | 425 | (defun auto-rename-tag--post-command () |
424 | | - "Do stuff after buffer is changed. |
425 | | -NOTE: Having this function is for `lsp` display issue with flycheck." |
| 426 | + "Do stuff after buffer is changed." |
426 | 427 | (auto-rename-tag--after-action)) |
427 | 428 |
|
428 | 429 | (defun auto-rename-tag--enable () |
429 | 430 | "Enable `auto-rename-tag' in current buffer." |
430 | 431 | (add-hook 'before-change-functions #'auto-rename-tag--before-change nil t) |
431 | | - (add-hook 'after-change-functions #'auto-rename-tag--after-change nil t) |
432 | 432 | (add-hook 'post-command-hook #'auto-rename-tag--post-command nil t)) |
433 | 433 |
|
434 | 434 | (defun auto-rename-tag--disable () |
435 | 435 | "Disable `auto-rename-tag' in current buffer." |
436 | 436 | (remove-hook 'before-change-functions #'auto-rename-tag--before-change t) |
437 | | - (remove-hook 'after-change-functions #'auto-rename-tag--after-change t) |
438 | 437 | (remove-hook 'post-command-hook #'auto-rename-tag--post-command t)) |
439 | 438 |
|
440 | 439 | ;;;###autoload |
|
0 commit comments