Use single hyphen in name of user configurable variables in khoj.el

- Follow convention, two hyphens indicate variable private to library
- Defcustom are user configurable variables. So they should have single -
- Use khoj-results-count variable directly in code
This commit is contained in:
Debanjum Singh Solanky 2022-08-09 20:49:34 +03:00
parent dddc57e132
commit f01fb16ebb

View file

@ -36,22 +36,22 @@
(require 'url) (require 'url)
(require 'json) (require 'json)
(defcustom khoj--server-url "http://localhost:8000" (defcustom khoj-server-url "http://localhost:8000"
"Location of Khoj API server." "Location of Khoj API server."
:group 'khoj :group 'khoj
:type 'string) :type 'string)
(defcustom khoj--image-width 156 (defcustom khoj-image-width 156
"Width of rendered images returned by Khoj." "Width of rendered images returned by Khoj."
:group 'khoj :group 'khoj
:type 'integer) :type 'integer)
(defcustom khoj--rerank-after-idle-time 1.0 (defcustom khoj-rerank-after-idle-time 1.0
"Idle time (in seconds) to trigger cross-encoder to rerank incremental search results." "Idle time (in seconds) to trigger cross-encoder to rerank incremental search results."
:group 'khoj :group 'khoj
:type 'float) :type 'float)
(defcustom khoj--results-count 5 (defcustom khoj-results-count 5
"Number of results to get from Khoj API for each query." "Number of results to get from Khoj API for each query."
:group 'khoj :group 'khoj
:type 'integer) :type 'integer)
@ -173,9 +173,9 @@ Use `which-key` if available, else display simple message in echo area"
(cdr (assoc 'score args)) (cdr (assoc 'score args))
(cdr (assoc 'metadata_score args)) (cdr (assoc 'metadata_score args))
(cdr (assoc 'image_score args)) (cdr (assoc 'image_score args))
khoj--server-url khoj-server-url
(cdr (assoc 'entry args)) (cdr (assoc 'entry args))
khoj--server-url khoj-server-url
(cdr (assoc 'entry args)) (cdr (assoc 'entry args))
(random 10000))) (random 10000)))
json-response))))) json-response)))))
@ -207,7 +207,7 @@ Use `which-key` if available, else display simple message in echo area"
(defun khoj--get-enabled-content-types () (defun khoj--get-enabled-content-types ()
"Get content types enabled for search from API" "Get content types enabled for search from API"
(let ((config-url (format "%s/config/data" khoj--server-url))) (let ((config-url (format "%s/config/data" khoj-server-url)))
(with-temp-buffer (with-temp-buffer
(erase-buffer) (erase-buffer)
(url-insert-file-contents config-url) (url-insert-file-contents config-url)
@ -222,9 +222,8 @@ Use `which-key` if available, else display simple message in echo area"
(defun khoj--construct-api-query (query search-type &optional rerank) (defun khoj--construct-api-query (query search-type &optional rerank)
(let ((rerank (or rerank "false")) (let ((rerank (or rerank "false"))
(results-count (or khoj--results-count 5))
(encoded-query (url-hexify-string query))) (encoded-query (url-hexify-string query)))
(format "%s/search?q=%s&t=%s&r=%s&n=%s" khoj--server-url encoded-query search-type rerank results-count))) (format "%s/search?q=%s&t=%s&r=%s&n=%s" khoj-server-url encoded-query search-type rerank khoj-results-count)))
(defun khoj--query-api-and-render-results (query search-type query-url buffer-name) (defun khoj--query-api-and-render-results (query search-type query-url buffer-name)
;; get json response from api ;; get json response from api
@ -279,7 +278,7 @@ Use `which-key` if available, else display simple message in echo area"
"Delete all network connections to khoj server" "Delete all network connections to khoj server"
(dolist (proc (process-list)) (dolist (proc (process-list))
(let ((proc-buf (buffer-name (process-buffer proc))) (let ((proc-buf (buffer-name (process-buffer proc)))
(khoj-network-proc-buf (string-join (split-string khoj--server-url "://") " "))) (khoj-network-proc-buf (string-join (split-string khoj-server-url "://") " ")))
(when (string-match (format "%s" khoj-network-proc-buf) proc-buf) (when (string-match (format "%s" khoj-network-proc-buf) proc-buf)
(delete-process proc))))) (delete-process proc)))))
@ -309,8 +308,8 @@ Use `which-key` if available, else display simple message in echo area"
(let* ((khoj-buffer-name (get-buffer-create khoj--buffer-name))) (let* ((khoj-buffer-name (get-buffer-create khoj--buffer-name)))
;; set khoj search type to last used or based on current buffer ;; set khoj search type to last used or based on current buffer
(setq khoj--search-type (or khoj--search-type (khoj--buffer-name-to-search-type (buffer-name)))) (setq khoj--search-type (or khoj--search-type (khoj--buffer-name-to-search-type (buffer-name))))
;; setup rerank to improve results once user idle for KHOJ--RERANK-AFTER-IDLE-TIME seconds ;; setup rerank to improve results once user idle for KHOJ-RERANK-AFTER-IDLE-TIME seconds
(setq khoj--rerank-timer (run-with-idle-timer khoj--rerank-after-idle-time t 'khoj--incremental-search t)) (setq khoj--rerank-timer (run-with-idle-timer khoj-rerank-after-idle-time t 'khoj--incremental-search t))
;; switch to khoj results buffer ;; switch to khoj results buffer
(switch-to-buffer khoj-buffer-name) (switch-to-buffer khoj-buffer-name)
;; open and setup minibuffer for incremental search ;; open and setup minibuffer for incremental search