Skip to content

Commit 9b74342

Browse files
authored
Merge pull request #651 from keram/interactive-user-errors
Use user-error instead of error in interactive functions that are directly invoked by the user
2 parents 49c6f38 + f25b37b commit 9b74342

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

idris-commands.el

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ A prefix argument SET-LINE forces loading but only up to the current line."
227227
(lambda (_condition)
228228
(when (member 'warnings-tree idris-warnings-printing)
229229
(idris-list-compiler-notes))))))
230-
(error "Cannot find file for current buffer")))
230+
(user-error "Cannot find file for current buffer")))
231231

232232
(defun idris-view-compiler-log ()
233233
"Jump to the log buffer, if it is open."
@@ -244,7 +244,7 @@ A prefix argument SET-LINE forces loading but only up to the current line."
244244
#'(lambda (w1 w2) (<= (overlay-start w1) (overlay-start w2))))))
245245
(if warnings-forward
246246
(goto-char (overlay-start (car warnings-forward)))
247-
(error "No warnings or errors until end of buffer"))))
247+
(user-error "No warnings or errors until end of buffer"))))
248248

249249
(defun idris-previous-error ()
250250
"Jump to the previous error overlay in the buffer."
@@ -253,7 +253,7 @@ A prefix argument SET-LINE forces loading but only up to the current line."
253253
#'(lambda (w1 w2) (>= (overlay-end w1) (overlay-end w2))))))
254254
(if warnings-backward
255255
(goto-char (overlay-end (car warnings-backward)))
256-
(error "No warnings or errors until beginning of buffer"))))
256+
(user-error "No warnings or errors until beginning of buffer"))))
257257

258258
(defun idris-load-file-sync ()
259259
"Pass the current buffer's file synchronously to the inferior Idris process.
@@ -280,7 +280,7 @@ This sets the load position to point, if there is one."
280280
(setq idris-currently-loaded-buffer (current-buffer))
281281
(idris-make-clean)
282282
(idris-update-loaded-region (car result)))))
283-
(error "Cannot find file for current buffer")))
283+
(user-error "Cannot find file for current buffer")))
284284

285285

286286

@@ -512,9 +512,9 @@ Useful for writing papers or slides."
512512
(fmt (completing-read "What format? " '("html", "latex") nil t nil nil "latex"))
513513
(width (read-string "How wide? " nil nil "80")))
514514
(if (<= (string-to-number width) 0)
515-
(error "Width must be positive")
515+
(user-error "Width must be positive")
516516
(if (< (length what) 1)
517-
(error "Nothing to pretty-print")
517+
(user-error "Nothing to pretty-print")
518518
(let ((text (idris-eval `(:interpret ,(concat ":pprint " fmt " " width " " what)))))
519519
(with-idris-info-buffer
520520
(insert (car text))
@@ -773,15 +773,15 @@ A plain prefix ARG causes the command to prompt for hints and recursion
773773
(idris-eval `(:proof-search ,(cdr what) ,(car what) ,hints ,@depth))
774774
))))
775775
(if (string= result "")
776-
(error "Nothing found")
776+
(user-error "Nothing found")
777777
(idris-replace-hole-with result))))))
778778

779779
(defun idris-proof-search-next ()
780780
"Replace the previous proof search result with the next one, if it exists.
781781
Idris 2 only."
782782
(interactive)
783783
(if (not proof-region-start)
784-
(error "You must proof search first before looking for subsequent proof results")
784+
(user-error "You must proof search first before looking for subsequent proof results")
785785
(let ((result (car (idris-eval `:proof-search-next))))
786786
(if (string= result "No more results")
787787
(message "No more results")
@@ -805,7 +805,7 @@ Idris 2 only."
805805
final-point
806806
(prefix (idris-line-indentation-for what)))
807807
(if (string= result "")
808-
(error "Nothing found")
808+
(user-error "Nothing found")
809809
(beginning-of-line)
810810
(forward-line)
811811
(while (and (not (eobp))
@@ -825,7 +825,7 @@ Idris 2 only."
825825
Idris 2 only."
826826
(interactive)
827827
(if (not def-region-start)
828-
(error "You must program search first before looking for subsequent program results")
828+
(user-error "You must program search first before looking for subsequent program results")
829829
(let ((result (car (idris-eval `:generate-def-next))))
830830
(if (string= result "No more results")
831831
(message "No more results")
@@ -841,7 +841,7 @@ Idris 2 only."
841841
(interactive)
842842
(let ((what (idris-thing-at-point)))
843843
(unless (car what)
844-
(error "Could not find a hole at point to refine by"))
844+
(user-error "Could not find a hole at point to refine by"))
845845
(idris-load-file-sync)
846846
(let ((results (car (idris-eval `(:intro ,(cdr what) ,(car what))))))
847847
(pcase results
@@ -853,7 +853,7 @@ Idris 2 only."
853853
(interactive "MRefine by: ")
854854
(let ((what (idris-thing-at-point)))
855855
(unless (car what)
856-
(error "Could not find a hole at point to refine by"))
856+
(user-error "Could not find a hole at point to refine by"))
857857
(idris-load-file-sync)
858858
(let ((result (car (idris-eval `(:refine ,(cdr what) ,(car what) ,name)))))
859859
(idris-replace-hole-with result))))
@@ -1015,7 +1015,7 @@ performed silently without confirmation from the user."
10151015
(ibc (concat (file-name-sans-extension fname) ".ibc")))
10161016
(if (not (member (file-name-extension fname)
10171017
'("idr" "lidr" "org" "markdown" "md")))
1018-
(error "The current file is not an Idris file")
1018+
(user-error "The current file is not an Idris file")
10191019
(when (or no-confirmation (y-or-n-p (concat "Really delete " ibc "?")))
10201020
(when (file-exists-p ibc)
10211021
(delete-file ibc)
@@ -1027,7 +1027,7 @@ performed silently without confirmation from the user."
10271027
It is an error if POS is not in the specified term. TERM should
10281028
be Idris's own serialization of the term in question."
10291029
(unless (equal (get-char-property pos 'idris-tt-term) term)
1030-
(error "Term not present at %s" pos))
1030+
(user-error "Term not present at %s" pos))
10311031
(save-excursion
10321032
;; Find the beginning of the active term
10331033
(goto-char pos)
@@ -1260,7 +1260,7 @@ of the term to replace."
12601260
(interactive)
12611261
(let ((files (idris-find-file-upwards "ipkg")))
12621262
(cond ((= (length files) 0)
1263-
(error "No .ipkg file found"))
1263+
(user-error "No .ipkg file found"))
12641264
((= (length files) 1)
12651265
(find-file (car files)))
12661266
(t (find-file (completing-read "Package file: " files nil t))))))
@@ -1280,7 +1280,7 @@ of the term to replace."
12801280
(first-mod (read-string
12811281
(format "First module name (%s): " module-name-suggestion)
12821282
nil nil module-name-suggestion)))
1283-
(when (file-exists-p create-in) (error "%s already exists" create-in))
1283+
(when (file-exists-p create-in) (user-error "%s already exists" create-in))
12841284
(when (string= src-dir "") (setq src-dir nil))
12851285
(make-directory create-in t)
12861286
(when src-dir (make-directory (concat (file-name-as-directory create-in) src-dir) t))

idris-prover.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Tactics are required to begin at the left margin."
204204
(next-tactic (idris-prover-find-tactic
205205
idris-prover-script-processed)))
206206
(if (null next-tactic)
207-
(error "At the end of the proof script")
207+
(user-error "At the end of the proof script")
208208
(let* ((tactic-start (car next-tactic))
209209
(tactic-end (cdr next-tactic))
210210
(tactic-text (buffer-substring-no-properties tactic-start
@@ -267,7 +267,7 @@ Tactics are required to begin at the left margin."
267267
#'(lambda (_result) t)
268268
#'(lambda (condition)
269269
(message (concat idris-prover-error-message-prefix condition))))
270-
(error "No proof in progress")))
270+
(user-error "No proof in progress")))
271271

272272
(easy-menu-define idris-prover-script-mode-menu idris-prover-script-mode-map
273273
"Menu for Idris prover scripts."
@@ -374,7 +374,7 @@ the length reported by Idris."
374374
(yes-or-no-p "Abandon proof and discard script? "))
375375
(if idris-prover-currently-proving
376376
(idris-eval (list :interpret (if idris-enable-elab-prover ":abandon" "abandon")) t)
377-
(error "No proof in progress"))))
377+
(user-error "No proof in progress"))))
378378

379379
(defun idris-prover-end ()
380380
"Remove buffers from proof mode and unset global state related to the prover."

idris-repl.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ files and this function is sufficient."
612612
(let ((file (or filename (idris-repl-history-file-f)))
613613
(hist (or history idris-repl-input-history)))
614614
(unless (file-writable-p file)
615-
(error (format "History file not writable: %s" file)))
615+
(user-error (format "History file not writable: %s" file)))
616616
(let ((hist (cl-subseq hist 0 (min (length hist) idris-repl-history-size))))
617617
(with-temp-file file
618618
(let ((cs idris-repl-history-file-coding-system)

0 commit comments

Comments
 (0)