Skip to content

Instantly share code, notes, and snippets.

@daniel-koudouna
Last active September 19, 2021 00:53
Show Gist options
  • Select an option

  • Save daniel-koudouna/39f03845914e34acde4d4c6a27c5176a to your computer and use it in GitHub Desktop.

Select an option

Save daniel-koudouna/39f03845914e34acde4d4c6a27c5176a to your computer and use it in GitHub Desktop.

Revisions

  1. daniel-koudouna revised this gist Feb 7, 2020. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions evil-insert-fix.el
    Original file line number Diff line number Diff line change
    @@ -25,18 +25,18 @@
    (let ((relative-loc (my:compare-with-end-of-word)))
    (cond ((my:is-end-of-line)
    (end-of-line)
    (funcall func))
    (call-interactively func))
    ((eq 0 relative-loc)
    (evil-forward-char)
    (funcall func))
    (call-interactively func))
    ((and (> 0 relative-loc) (not (my:point-is-space)))
    (evil-forward-word-end)
    (if (my:is-end-of-line)
    (end-of-line)
    (evil-forward-char))
    (funcall func))
    (call-interactively func))
    (t
    (funcall func)))))
    (call-interactively func)))))

    ;; Example usage
    (defun my:reftex-citation ()
  2. daniel-koudouna created this gist Feb 7, 2020.
    46 changes: 46 additions & 0 deletions evil-insert-fix.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    (defun my:is-end-of-line ()
    "Compare point with end of line."
    (let* ((pos (current-column))
    (end-pos (save-excursion
    (evil-end-of-line)
    (current-column))))
    (eq pos end-pos)))

    (defun my:compare-with-end-of-word ()
    "Compare point with end of word."
    (let* ((pos (current-column))
    (end-pos (save-excursion
    (evil-backward-word-begin)
    (evil-forward-word-end)
    (current-column))))
    (- pos end-pos)))

    (defun my:point-is-space ()
    "Check if point is whitespace."
    (char-equal ?\s (char-after)))

    (defun my:insert-after (func)
    "Run FUNC after the end of word, ignoring whitespace."
    (interactive)
    (let ((relative-loc (my:compare-with-end-of-word)))
    (cond ((my:is-end-of-line)
    (end-of-line)
    (funcall func))
    ((eq 0 relative-loc)
    (evil-forward-char)
    (funcall func))
    ((and (> 0 relative-loc) (not (my:point-is-space)))
    (evil-forward-word-end)
    (if (my:is-end-of-line)
    (end-of-line)
    (evil-forward-char))
    (funcall func))
    (t
    (funcall func)))))

    ;; Example usage
    (defun my:reftex-citation ()
    "Custom reftex to ensure citations appear at the end of words."
    (interactive)
    (my:insert-after 'reftex-citation))