From 07e9e4ecc3561a8c02e264e88e65f07c89b1710d Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Mon, 23 Jan 2023 18:02:47 -0300 Subject: [PATCH] Get current paragraph text when point at start of paragraph in khoj.el Previously if cursor was at start of current paragraph, it would get text for the current and next paragraph, instead of just the current one --- src/interface/emacs/khoj.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/interface/emacs/khoj.el b/src/interface/emacs/khoj.el index a138c4ac..3a75cf36 100644 --- a/src/interface/emacs/khoj.el +++ b/src/interface/emacs/khoj.el @@ -417,10 +417,16 @@ Use `which-key` if available, else display simple message in echo area" ;; trim trailing whitespaces from text (replace-regexp-in-string "[ \t\n]*$" "" - ;; get text of current entry - (buffer-substring-no-properties - (save-excursion (backward-paragraph) (point)) - (save-excursion (forward-paragraph) (point))))))) + (cond + ;; when at beginning of a middle paragraph + ((and (looking-at paragraph-start) (not (equal (point) (point-min)))) + (buffer-substring-no-properties + (save-excursion (backward-paragraph) (point)) + (point))) + ;; else + (t (buffer-substring-no-properties + (save-excursion (backward-paragraph) (point)) + (save-excursion (forward-paragraph) (point))))))))) (defun khoj--find-similar (&optional content-type) "Find items of CONTENT-TYPE in khoj index similar to text surrounding point."