From be1e69e423588898c758b1a85e9fef85824b1259 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Thu, 17 Oct 2024 08:57:34 +0800 Subject: [PATCH] Fix issue #1077, org-mode input bound use "string" branch. --- acm/acm-backend-capf.el | 1 + acm/acm.el | 45 +++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/acm/acm-backend-capf.el b/acm/acm-backend-capf.el index 2827c48df6..c9efab2e15 100644 --- a/acm/acm-backend-capf.el +++ b/acm/acm-backend-capf.el @@ -114,6 +114,7 @@ anaconda-mode redis-mode lisp-mode + org-mode ) "The mode list to support capf." :type 'cons) diff --git a/acm/acm.el b/acm/acm.el index 4653847bcc..9f13d69dcb 100644 --- a/acm/acm.el +++ b/acm/acm.el @@ -377,27 +377,28 @@ So we use `minor-mode-overriding-map-alist' to override key, make sure all keys (<= (match-beginning 2) (point)))) (defun acm-get-input-prefix-bound () - (pcase acm-input-bound-style - ("symbol" - (bounds-of-thing-at-point 'symbol)) - ("org-roam" - (when (org-in-regexp org-roam-bracket-completion-re 1) - (cons (match-beginning 2) - (match-end 2)))) - ("string" - (cons (point) - (save-excursion - (if (search-backward-regexp "\\s-" (point-at-bol) t) - (progn - (forward-char) - (point)) - (point-at-bol))))) - ("ascii" - (when-let ((bound (bounds-of-thing-at-point 'symbol))) - (let* ((keyword (buffer-substring-no-properties (car bound) (cdr bound))) - (offset (or (string-match "[[:nonascii:]]+" (reverse keyword)) - (length keyword)))) - (cons (- (cdr bound) offset) (cdr bound))))))) + (cond + ((or (equal "string" acm-input-bound-style) + (derived-mode-p 'org-mode)) + (cons (point) + (save-excursion + (if (search-backward-regexp "\\s-" (point-at-bol) t) + (progn + (forward-char) + (point)) + (point-at-bol))))) + ((equal "symbol" acm-input-bound-style) + (bounds-of-thing-at-point 'symbol)) + ((equal "org-roam" acm-input-bound-style) + (when (org-in-regexp org-roam-bracket-completion-re 1) + (cons (match-beginning 2) + (match-end 2)))) + ((equal "ascii" acm-input-bound-style) + (when-let ((bound (bounds-of-thing-at-point 'symbol))) + (let* ((keyword (buffer-substring-no-properties (car bound) (cdr bound))) + (offset (or (string-match "[[:nonascii:]]+" (reverse keyword)) + (length keyword)))) + (cons (- (cdr bound) offset) (cdr bound))))))) (defun acm-get-input-prefix () "Get user input prefix." @@ -538,7 +539,7 @@ Only calculate template candidate when type last character." (setq file-words-candidates (acm-remove-duplicate-candidates file-words-candidates lsp-labels))) - + (setq mode-candidates (apply #'append (mapcar (lambda (mode-candidate-name) (pcase mode-candidate-name