From dbd6a655f859ee7520933ae76d0c210dc24bb059 Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Sun, 10 Jan 2021 20:50:06 +0100 Subject: [PATCH] Fix cursor point --- burn.el | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/burn.el b/burn.el index bd27e41..06ae1cd 100644 --- a/burn.el +++ b/burn.el @@ -4,7 +4,7 @@ ;; Authors: Erick Navarro , Andros Fenollosa ;; URL: https://github.com/erickgnavar/burn.el ;; Version: 0.2.0 -;; SPDX-License-Identifier: GNU General Public License v3.0 or later +;; SPDX-License Identifier: GNU General Public License v3.0 or later ;;; Commentary: ;; Replace the buffer content with 🔥. @@ -13,23 +13,20 @@ (setf burn--emoji "🔥") -(defun burn--is-exist-emoji () - (not (null (string-match-p burn--emoji (buffer-string))))) - (defun burn--is-empty () - (= 0 (length (replace-regexp-in-string (concat "\\`[ \t\n" burn--emoji "]*") "" (replace-regexp-in-string (concat "[ \t\n" burn--emoji "]*\\'") "" (buffer-string)))))) + (= 0 (length + (replace-regexp-in-string (concat "\\`[ \t\n" burn--emoji "]*") "" + (replace-regexp-in-string (concat "[ \t\n" burn--emoji "]*\\'") "" (buffer-string)))))) (defun burn--replace-backward-at-point () "Replace the backwards character at point with burn--emoji." - (re-search-backward (concat "[^" burn--emoji " \t\n]") 1) - (delete-char 1) - (insert burn--emoji)) + (when (re-search-backward (concat "[^ \t\n" burn--emoji "]") nil :noerr) + (replace-match burn--emoji))) (defun burn--replace-forward-at-point () "Replace the forward character at point with burn--emoji." - (re-search-forward (concat "[^" burn--emoji " \t\n]") 1) - (delete-char 1) - (insert burn--emoji)) + (when (re-search-forward (concat "[^ \t\n" burn--emoji "]") nil :noerr) + (replace-match burn--emoji))) (defun burn-code () "Replace code with burn--emoji." @@ -39,7 +36,8 @@ (burn--replace-backward-at-point) (burn--replace-forward-at-point) ) - ) + ;; Clear burn--emoji + (set-buffer-modified-p "")) ;;; burn.el ends here