Skip to content

Commit

Permalink
Handle a primitive error in bounds appropriately
Browse files Browse the repository at this point in the history
  • Loading branch information
countvajhula committed Jun 15, 2024
1 parent 400a889 commit b9fbd99
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 68 deletions.
30 changes: 18 additions & 12 deletions symex-primitives.el
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,24 @@ from the buffer."
WHAT could be `this`, `next`, or `previous`."
(let ((result))
(cond ((eq 'this what)
(setq result (symex-remove 1)))
((eq 'previous what)
(when (symex--previous-p)
(symex--go-backward)
(setq result (symex-remove 1))))
((eq 'next what)
(when (symex--next-p)
(save-excursion
(symex--go-forward)
(setq result (symex-remove 1)))))
(t (error "Invalid argument for primitive delete!")))
(condition-case nil
(cond ((eq 'this what)
(setq result (symex-remove 1)))
((eq 'previous what)
(when (symex--previous-p)
(symex--go-backward)
(setq result (symex-remove 1))))
((eq 'next what)
(when (symex--next-p)
(save-excursion
(symex--go-forward)
(setq result (symex-remove 1)))))
(t (error "Invalid argument for primitive delete!")))
;; if unable to delete, return nil instead of
;; raising an error. nil is used in the evaluator
;; to mean failed, so the traversal would stop there
;; as expected.
(error nil))
result))

(defun symex-prim-paste (where)
Expand Down
107 changes: 54 additions & 53 deletions symex-transformations-lisp.el
Original file line number Diff line number Diff line change
Expand Up @@ -121,61 +121,62 @@ text, on the respective side."

(defun symex-lisp--padding (&optional before)
"Determine paste padding needed for current point position."
(let* ((after (not before))
(island
(and (bolp)
(condition-case nil
(save-excursion (forward-sexp)
(eolp))
(error nil))))
(at-eob
(condition-case nil
(save-excursion (forward-sexp)
(eobp))
(error nil)))
(previous-line-empty
(symex--previous-line-empty-p))
(next-line-empty
(symex--following-line-empty-p))
(surrounding-lines-empty (and previous-line-empty
next-line-empty))
(paste-text-contains-newlines
(seq-contains-p (symex--current-kill) ?\n))
(at-eol (condition-case nil
(if (symex-inside-empty-form-p)
""
(let* ((after (not before))
(island
(and (bolp)
(condition-case nil
(save-excursion (forward-sexp)
(eolp))
(error nil)))
(multiline (let ((original-line (line-number-at-pos)))
(condition-case nil
(save-excursion (forward-sexp)
(not (= original-line
(line-number-at-pos))))
(error nil)))))
(cond ((and island
;; if we're at the toplevel, on an "island" symex
;; (i.e. with no peers occupying the same lines),
(or (and after next-line-empty)
;; and if the side we want to paste on already
;; contains an empty line,
(and before previous-line-empty)
;; or if we happen to be at the end of the buffer
;; for pasting after, then check the opposite side
;; instead for the clue on what's expected
(and at-eob previous-line-empty))
;; and if the text to be pasted contains newlines, or
;; if both surrounding lines are empty _and_ we aren't
;; at the first symex
(or paste-text-contains-newlines
(and surrounding-lines-empty
(not (symex--point-at-first-symex-p)))))
;; then we typically want an extra newline separator
"\n\n")
((or (symex--point-at-indentation-p)
at-eol
multiline)
"\n")
((symex-inside-empty-form-p) "")
(t " "))))
(error nil))))
(at-eob
(condition-case nil
(save-excursion (forward-sexp)
(eobp))
(error nil)))
(previous-line-empty
(symex--previous-line-empty-p))
(next-line-empty
(symex--following-line-empty-p))
(surrounding-lines-empty (and previous-line-empty
next-line-empty))
(paste-text-contains-newlines
(seq-contains-p (symex--current-kill) ?\n))
(at-eol (condition-case nil
(save-excursion (forward-sexp)
(eolp))
(error nil)))
(multiline (let ((original-line (line-number-at-pos)))
(condition-case nil
(save-excursion (forward-sexp)
(not (= original-line
(line-number-at-pos))))
(error nil)))))
(cond ((and island
;; if we're at the toplevel, on an "island" symex
;; (i.e. with no peers occupying the same lines),
(or (and after next-line-empty)
;; and if the side we want to paste on already
;; contains an empty line,
(and before previous-line-empty)
;; or if we happen to be at the end of the buffer
;; for pasting after, then check the opposite side
;; instead for the clue on what's expected
(and at-eob previous-line-empty))
;; and if the text to be pasted contains newlines, or
;; if both surrounding lines are empty _and_ we aren't
;; at the first symex
(or paste-text-contains-newlines
(and surrounding-lines-empty
(not (symex--point-at-first-symex-p)))))
;; then we typically want an extra newline separator
"\n\n")
((or (symex--point-at-indentation-p)
at-eol
multiline)
"\n")
(t " ")))))

(defun symex-lisp--paste-before ()
"Paste before symex."
Expand Down
9 changes: 6 additions & 3 deletions symex-ui.el
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@
"Update the highlight overlay to match the start/end position of NODE."
(when symex--current-overlay
(delete-overlay symex--current-overlay))
(setq-local symex--current-overlay
(make-overlay (symex--get-starting-point)
(symex--get-end-point 1)))
(let* ((start (symex--get-starting-point))
(end (condition-case nil
(symex--get-end-point 1)
(error start))))
(setq-local symex--current-overlay
(make-overlay start end)))
(overlay-put symex--current-overlay 'face 'symex--current-node-face))

(defun symex--overlay-active-p ()
Expand Down

0 comments on commit b9fbd99

Please sign in to comment.