;; Implementation from Agustin Martin with additional regexp-quote (defun my-test-agustin (word bound &optional ignore-case) (save-excursion (let ((r '()) (inhibit-point-motion-hooks t) (flyspell-not-casechars (flyspell-get-not-casechars)) p) (while (and (not r) (setq p (re-search-backward (concat "\\(" flyspell-not-casechars "\\|\\b\\)" "\\(" (regexp-quote word) "\\)" flyspell-not-casechars ) bound t))) (goto-char (match-beginning 2)) (let ((lw (flyspell-get-word))) (if (and (consp lw) (if ignore-case (string-equal (downcase (car lw)) (downcase word)) (string-equal (car lw) word))) (setq r p) (goto-char p)))) r))) (defun my-test-concat-up (word bound &optional ignore-case) (save-excursion (let* ((r '()) (inhibit-point-motion-hooks t) (flyspell-not-casechars (flyspell-get-not-casechars)) (word-re (concat "\\(" flyspell-not-casechars "\\|\\b\\)" "\\(" (regexp-quote word) "\\)" flyspell-not-casechars)) p) (while (and (not r) (setq p (re-search-backward word-re bound t))) (goto-char (match-beginning 2)) (let ((lw (flyspell-get-word))) (if (and (consp lw) (if ignore-case (string-equal (downcase (car lw)) (downcase word)) (string-equal (car lw) word))) (setq r p) (goto-char p)))) r))) (defun my-test-concat-up-goto (word bound &optional ignore-case) (save-excursion (let* ((r '()) (inhibit-point-motion-hooks t) (flyspell-not-casechars (flyspell-get-not-casechars)) (word-re (concat "\\(" flyspell-not-casechars "\\|\\b\\)" "\\(" (regexp-quote word) "\\)" flyspell-not-casechars)) p) (while (and (not r) (setq p (and (re-search-backward word-re bound t) (goto-char (match-beginning 2))))) (let ((lw (flyspell-get-word))) (if (and (consp lw) (if ignore-case (string-equal (downcase (car lw)) (downcase word)) (string-equal (car lw) word))) (setq r p) (goto-char p)))) r))) (defun my-test-concat-up-goto-notcap (word bound &optional ignore-case) (save-excursion (let* ((r '()) (inhibit-point-motion-hooks t) (flyspell-not-casechars (flyspell-get-not-casechars)) (word-re (concat "\\(?:" flyspell-not-casechars "\\|\\b\\)" "\\(" (regexp-quote word) "\\)" flyspell-not-casechars)) p) (while (and (not r) (setq p (and (re-search-backward word-re bound t) (goto-char (match-beginning 2))))) (let ((lw (flyspell-get-word))) (if (and (consp lw) (if ignore-case (string-equal (downcase (car lw)) (downcase word)) (string-equal (car lw) word))) (setq r p) (goto-char p)))) r))) (defun my-test-concat-up-goto-notcap-bob (word bound &optional ignore-case) (save-excursion (let* ((r '()) (inhibit-point-motion-hooks t) (flyspell-not-casechars (flyspell-get-not-casechars)) (word-re (concat "\\(?:" flyspell-not-casechars "\\|\\`\\)" "\\(" (regexp-quote word) "\\)" flyspell-not-casechars)) p) (while (and (not r) (setq p (and (re-search-backward word-re bound t) (goto-char (match-beginning 2))))) (let ((lw (flyspell-get-word))) (if (and (consp lw) (if ignore-case (string-equal (downcase (car lw)) (downcase word)) (string-equal (car lw) word))) (setq r p) (goto-char p)))) r))) (defun my-test-concat-up-goto-notcap-bob-bobp (word bound &optional ignore-case) (save-excursion (let* ((r '()) (inhibit-point-motion-hooks t) (flyspell-not-casechars (flyspell-get-not-casechars)) (word-re (concat "\\(?:" flyspell-not-casechars "\\|\\`\\)" (regexp-quote word) flyspell-not-casechars)) p) (while (and (not r) (setq p (and (re-search-backward word-re bound t) (unless (bobp) (forward-char) (point))))) (let ((lw (flyspell-get-word))) (if (and (consp lw) (if ignore-case (string-equal (downcase (car lw)) (downcase word)) (string-equal (car lw) word))) (setq r p) (goto-char p)))) r))) ;; Wrong (defun my-test-concat-up-goto-notcap-nobob-bobp (word bound &optional ignore-case) (save-excursion (let* ((r '()) (inhibit-point-motion-hooks t) (flyspell-not-casechars (flyspell-get-not-casechars)) (word-re (concat flyspell-not-casechars (regexp-quote word) flyspell-not-casechars)) p) (while (and (not r) (setq p (and (re-search-backward word-re bound t) (unless (bobp) (forward-char) (point))))) (let ((lw (flyspell-get-word))) (if (and (consp lw) (if ignore-case (string-equal (downcase (car lw)) (downcase word)) (string-equal (car lw) word))) (setq r p) (goto-char p)))) (unless r (setq p (goto-char (point-min))) (let ((lw (flyspell-get-word))) (if (and (consp lw) (if ignore-case (string-equal (downcase (car lw)) (downcase word)) (string-equal (car lw) word))) (setq r p)))) r))) ;; Wrong (defun my-test-concat-up-goto-notcap-nobob-nobobp (word bound &optional ignore-case) (save-excursion (let* ((r '()) (inhibit-point-motion-hooks t) (flyspell-not-casechars (flyspell-get-not-casechars)) (word-re (concat flyspell-not-casechars (regexp-quote word) flyspell-not-casechars)) p) (while (and (not r) (setq p (and (re-search-backward word-re bound t) (progn (forward-char) (point))))) (let ((lw (flyspell-get-word))) (if (and (consp lw) (if ignore-case (string-equal (downcase (car lw)) (downcase word)) (string-equal (car lw) word))) (setq r p) (goto-char p)))) (unless r (setq p (goto-char (point-min))) (let ((lw (flyspell-get-word))) (if (and (consp lw) (if ignore-case (string-equal (downcase (car lw)) (downcase word)) (string-equal (car lw) word))) (setq r p)))) r))) ;; Wrong (defun my-test-goto-notcap-nobob-nobobp (word bound &optional ignore-case) (save-excursion (let* ((r '()) (inhibit-point-motion-hooks t) (flyspell-not-casechars (flyspell-get-not-casechars)) p) (while (and (not r) (setq p (and (re-search-backward (concat flyspell-not-casechars (regexp-quote word) flyspell-not-casechars) bound t) (progn (forward-char) (point))))) (let ((lw (flyspell-get-word))) (if (and (consp lw) (if ignore-case (string-equal (downcase (car lw)) (downcase word)) (string-equal (car lw) word))) (setq r p) (goto-char p)))) (unless r (setq p (goto-char (point-min))) (let ((lw (flyspell-get-word))) (if (and (consp lw) (if ignore-case (string-equal (downcase (car lw)) (downcase word)) (string-equal (car lw) word))) (setq r p)))) r))) (defun my-test-concat-up-goto-notcap-nobob-bobp-fixed (word bound &optional ignore-case) (save-excursion (let* ((r '()) (inhibit-point-motion-hooks t) (flyspell-not-casechars (flyspell-get-not-casechars)) (word-re (concat flyspell-not-casechars (regexp-quote word) flyspell-not-casechars)) p) (while (and (not r) (setq p (and (re-search-backward word-re bound t) (unless (bobp) (forward-char) (point))))) (let ((lw (flyspell-get-word))) (if (and (consp lw) (if ignore-case (string-equal (downcase (car lw)) (downcase word)) (string-equal (car lw) word))) (setq r p) (goto-char p)))) (unless r (let ((pos (point))) (setq p (goto-char (point-min))) (and (search-forward word (length word) t) (let ((lw (flyspell-get-word))) (if (and (consp lw) (if ignore-case (string-equal (downcase (car lw)) (downcase word)) (string-equal (car lw) word))) (setq r p)))))) r))) (defun my-try (word) (message "%s" (mapconcat (lambda (func) (end-of-buffer) (let* ((time (current-time)) (res (apply func '("nd" nil)))) (format ":>: %s %S =%S %S" word (subtract-time (current-time) time) res func))) (let ((lst '(my-test-agustin my-test-concat-up my-test-concat-up-goto my-test-concat-up-goto-notcap my-test-concat-up-goto-notcap-bob my-test-concat-up-goto-notcap-bob-bobp my-test-concat-up-goto-notcap-nobob-bobp my-test-concat-up-goto-notcap-nobob-nobobp my-test-goto-notcap-nobob-nobobp my-test-concat-up-goto-notcap-nobob-bobp-fixed))) (concatenate 'list lst lst)) "\n")))