branch: elpa/nix-mode commit 84996a780496ef9a1c7762b31c17642edeeb78f0 Author: Matthew Bauer <mjbaue...@gmail.com> Commit: Matthew Bauer <mjbaue...@gmail.com>
Fix checkdoc errors. --- nix-company.el | 11 ++++++- nix-mode.el | 27 +++++++++++++---- nix-prettify-mode.el | 2 +- nix-repl.el | 80 +++++++++++++++++++++++++++---------------------- tests/nix-mode-tests.el | 7 +++++ 5 files changed, 83 insertions(+), 44 deletions(-) diff --git a/nix-company.el b/nix-company.el index a1b589abf5..f097acbe2b 100644 --- a/nix-company.el +++ b/nix-company.el @@ -9,7 +9,11 @@ (require 'nix-repl) (require 'cl) -(defun company-nix (command &optional arg &rest ignored) +(defun company-nix (command &optional arg &rest _) + "Company backend for Nix. + +COMMAND company command +ARG company argument" (interactive '(interactive)) (case command (interactive (company-begin-backend 'company-nix)) @@ -20,6 +24,7 @@ (sorted t))) (defun nix-grab-attr-path () + "Get Nix attribute path at point." (if (looking-at "[^a-zA-Z0-9'\\-_\\.]") (buffer-substring (point) (save-excursion (skip-chars-backward "a-zA-Z0-9'\\-_\\.") (point))) @@ -28,6 +33,9 @@ "")))) (defun nix--get-company-buffer (&optional buffer) + "Get the Nix repl buffer for company. + +BUFFER check for Nix-REPL in current buffer" (let* ((buf (or buffer (current-buffer))) (repl-buf (get-buffer "*Nix-REPL*"))) (if (or (equal buf "*Nix-REPL*") (equal buf repl-buf)) @@ -38,6 +46,7 @@ (defvar nix--company-last-buffer nil) (defun nix--get-company-backend-buffer (buffer) + "Get Nix company backend from BUFFER." (let* ((buf-file (buffer-file-name buffer)) (backend-buf (get-buffer-create nix-company-backend-buffer-name)) (last-buf nix--company-last-buffer) diff --git a/nix-mode.el b/nix-mode.el index a2c4e2bd2b..97162fd237 100644 --- a/nix-mode.el +++ b/nix-mode.el @@ -126,27 +126,36 @@ t)))))))) (defun nix--mark-string (pos string-type) + "Mark string as a Nix string. + +POS position of start of string +STRING-TYPE type of string based off of Emacs syntax table types" (put-text-property pos (1+ pos) 'syntax-table (string-to-syntax "|")) (put-text-property pos (1+ pos) 'nix-string-type string-type)) (defun nix--get-parse-state (pos) + "Get the result of `syntax-ppss' at POS." (save-excursion (save-match-data (syntax-ppss pos)))) (defun nix--get-string-type (parse-state) + "Get the type of string based on PARSE-STATE." (let ((string-start (nth 8 parse-state))) (and string-start (get-text-property string-start 'nix-string-type)))) (defun nix--open-brace-string-type (parse-state) + "Determine if this is an open brace string type based on PARSE-STATE." (let ((open-brace (nth 1 parse-state))) (and open-brace (get-text-property open-brace 'nix-string-type)))) (defun nix--open-brace-antiquote-p (parse-state) + "Determine if this is an open brace antiquote based on PARSE-STATE." (let ((open-brace (nth 1 parse-state))) (and open-brace (get-text-property open-brace 'nix-syntax-antiquote)))) (defun nix--single-quotes () + "Handle Nix single quotes." (let* ((start (match-beginning 0)) (end (match-end 0)) (context (nix--get-parse-state start)) @@ -166,6 +175,7 @@ (nix--mark-string (1- end) ?\'))))))) (defun nix--escaped-antiquote-dq-style () + "Handle Nix escaped antiquote dq style." (let* ((start (match-beginning 0)) (ps (nix--get-parse-state start)) (string-type (nix--get-string-type ps))) @@ -173,6 +183,7 @@ (nix--antiquote-open-at (1+ start) ?\')))) (defun nix--double-quotes () + "Handle Nix double quotes." (let* ((pos (match-beginning 0)) (ps (nix--get-parse-state pos)) (string-type (nix--get-string-type ps))) @@ -180,14 +191,16 @@ (nix--mark-string pos ?\")))) (defun nix--antiquote-open-at (pos string-type) - (put-text-property pos (1+ pos) - 'syntax-table (string-to-syntax "|")) - (put-text-property pos (+ 2 pos) - 'nix-string-type string-type) - (put-text-property (1+ pos) (+ 2 pos) - 'nix-syntax-antiquote t)) + "Handle Nix antiquote open at based on POS and STRING-TYPE." + (put-text-property pos (1+ pos) + 'syntax-table (string-to-syntax "|")) + (put-text-property pos (+ 2 pos) + 'nix-string-type string-type) + (put-text-property (1+ pos) (+ 2 pos) + 'nix-syntax-antiquote t)) (defun nix--antiquote-open () + "Handle Nix antiquote open." (let* ((start (match-beginning 0)) (ps (nix--get-parse-state start)) (string-type (nix--get-string-type ps))) @@ -195,6 +208,7 @@ (nix--antiquote-open-at start string-type)))) (defun nix--antiquote-close-open () + "Handle Nix antiquote close then open." (let* ((start (match-beginning 0)) (ps (nix--get-parse-state start)) (string-type (nix--get-string-type ps))) @@ -210,6 +224,7 @@ 'nix-syntax-antiquote t)))))) (defun nix--antiquote-close () + "Handle Nix antiquote close." (let* ((start (match-beginning 0)) (ps (nix--get-parse-state start))) (unless (nix--get-string-type ps) diff --git a/nix-prettify-mode.el b/nix-prettify-mode.el index 3d17670e72..0ae8f28099 100644 --- a/nix-prettify-mode.el +++ b/nix-prettify-mode.el @@ -62,7 +62,7 @@ removed only from strings matching `nix-prettify-regexp', so that compositions created by other modes are left untouched. Set this variable to non-nil, if you want to remove any -composition unconditionally (like `prettify-symbols-mode' does). +composition unconditionally (like variable `prettify-symbols-mode' does). Most likely it will do no harm and will make the process of disabling `nix-prettify-mode' a little faster." :type 'boolean diff --git a/nix-repl.el b/nix-repl.el index 40d7c41d4a..32a04101b4 100644 --- a/nix-repl.el +++ b/nix-repl.el @@ -22,6 +22,19 @@ (setq-local comint-prompt-regexp nix-prompt-regexp) (setq-local comint-prompt-read-only t)) +(defmacro nix--with-temp-process-filter (proc &rest body) + "Use temp process PROC filter on BODY." + (declare (indent defun)) + `(let* ((buf (generate-new-buffer " *temp-process-output*")) + (proc-filter-saved (process-filter ,proc)) + (proc-marker (with-current-buffer buf (point-marker)))) + (set-process-filter ,proc (nix--process-filter buf proc-marker)) + (unwind-protect + (with-current-buffer buf + ,@body) + (set-process-filter ,proc proc-filter-saved) + (kill-buffer buf)))) + (defun nix-repl-show () "Load the Nix-REPL." (interactive) @@ -32,58 +45,53 @@ (nix-repl-mode))) (defun nix--make-repl-in-buffer (buffer) + "Make Nix Repl in BUFFER." (make-comint-in-buffer "Nix-REPL" buffer nix-repl-executable)) (defun nix-get-completions (proc prefix) + "Get Nix completions from Nix-repl process PROC and based off of PREFIX." (save-match-data (nix--with-temp-process-filter proc - (goto-char (point-min)) - (process-send-string proc (concat prefix "\t\"" (nix--char-with-ctrl ?a) "\"\n")) - (setq i 0) - (while (and (< (setq i (1+ i)) 100) - (not (search-forward-regexp "\"\\([^\"]*\\)\"[\n]*nix-repl>" nil t))) - (sleep-for 0.01)) - (let ((new-prefix (match-string 1)) - (start-compl (point))) - (if (string-suffix-p " " new-prefix) - (list (substring new-prefix 0 -1)) - (process-send-string proc (concat new-prefix "\t\t" (nix--char-with-ctrl ?u) "\n")) - (goto-char start-compl) - (setq i 0) - (while (and (< (setq i (1+ i)) 100) - (not (search-forward-regexp - "[\n]+nix-repl>\\|Display all \\([0-9]+\\)" nil t))) - (sleep-for 0.01)) - (if (match-string 1) - (progn - (process-send-string proc "n") - '()) - (search-backward "\n" nil t) - (split-string (buffer-substring start-compl (1- (point)))))))))) + (goto-char (point-min)) + (process-send-string proc (concat prefix "\t\"" (nix--char-with-ctrl ?a) "\"\n")) + (setq i 0) + (while (and (< (setq i (1+ i)) 100) + (not (search-forward-regexp "\"\\([^\"]*\\)\"[\n]*nix-repl>" nil t))) + (sleep-for 0.01)) + (let ((new-prefix (match-string 1)) + (start-compl (point))) + (if (string-suffix-p " " new-prefix) + (list (substring new-prefix 0 -1)) + (process-send-string proc (concat new-prefix "\t\t" (nix--char-with-ctrl ?u) "\n")) + (goto-char start-compl) + (setq i 0) + (while (and (< (setq i (1+ i)) 100) + (not (search-forward-regexp + "[\n]+nix-repl>\\|Display all \\([0-9]+\\)" nil t))) + (sleep-for 0.01)) + (if (match-string 1) + (progn + (process-send-string proc "n") + '()) + (search-backward "\n" nil t) + (split-string (buffer-substring start-compl (1- (point)))))))))) (defun nix--send-repl (input &optional process mute) + "Send INPUT to PROCESS. + +MUTE if true then don’t alert user." (let ((proc (or process (get-buffer-process (current-buffer))))) (if mute (nix--with-temp-process-filter proc - (process-send-string proc input)) + (process-send-string proc input)) (process-send-string proc input)))) (defun nix--char-with-ctrl (char) + "Generate control character CHAR." (char-to-string (logand #b10011111 char))) -(defmacro nix--with-temp-process-filter (proc &rest body) - (declare (indent defun)) - `(let* ((buf (generate-new-buffer " *temp-process-output*")) - (proc-filter-saved (process-filter ,proc)) - (proc-marker (with-current-buffer buf (point-marker)))) - (set-process-filter ,proc (nix--process-filter buf proc-marker)) - (unwind-protect - (with-current-buffer buf - ,@body) - (set-process-filter ,proc proc-filter-saved) - (kill-buffer buf)))) - (defun nix--process-filter (buf marker) + "Process filter for Nix-rel buffer BUF at MARKER." (lambda (proc string) (when (buffer-live-p buf) (with-current-buffer buf diff --git a/tests/nix-mode-tests.el b/tests/nix-mode-tests.el index 3c004bb1a6..d92a02fef5 100644 --- a/tests/nix-mode-tests.el +++ b/tests/nix-mode-tests.el @@ -1,3 +1,9 @@ +;;; nix-mode-tests.el -- test nix-mode + +;;; Commentary: + +;;; Code: + (require 'ert) (require 'nix-mode) @@ -21,3 +27,4 @@ (eq (nix--get-string-type (nix--get-parse-state (point))) nil)))) (provide 'nix-mode-tests) +;;; nix-mode-tests.el ends here