Refactor hooks for better handling of phrase eval, closes #201.
The patch tries to improve on the current way of evaluating a phrase and skipping to the next. It removes both `utop-skip-to-end-of-phrase` and `utop-skip-blank-and-comments`, but adds `utop-next-phrase-beginning`. We assume `utop-discover-phrase` is always returning the end position as at end of a `;;`. Thereafter we use `utop-next-phrase-beginning` to skip to the next phase if `utop-skip-after-eval-phrase` is non-nil.
This commit is contained in:
parent
ef1e2a619d
commit
d9f198899b
|
@ -217,14 +217,13 @@ Useful as file variable."))
|
||||||
"Name of preprocesor. Currently supported camlp4o, camlp4r.
|
"Name of preprocesor. Currently supported camlp4o, camlp4r.
|
||||||
Useful as file variable."))
|
Useful as file variable."))
|
||||||
|
|
||||||
(defvar utop-skip-blank-and-comments 'utop-compat-skip-blank-and-comments
|
(defvar utop-next-phrase-beginning 'utop-compat-next-phrase-beginning
|
||||||
"The function used to skip blanks and comments.")
|
"The function used to find the beginning of the next phrase.")
|
||||||
|
|
||||||
(defvar utop-skip-to-end-of-phrase 'utop-compat-skip-to-end-of-phrase
|
|
||||||
"The function used to find the end of a phrase")
|
|
||||||
|
|
||||||
(defvar utop-discover-phrase 'utop-compat-discover-phrase
|
(defvar utop-discover-phrase 'utop-compat-discover-phrase
|
||||||
"The function used to discover a phrase")
|
"The function used to discover a phrase.
|
||||||
|
It should return a triple (begin-pos, end-pos,
|
||||||
|
end-pos-with-comments)." )
|
||||||
|
|
||||||
(defvar utop-skip-after-eval-phrase t
|
(defvar utop-skip-after-eval-phrase t
|
||||||
"Whether to skip to next phrase after evaluation.
|
"Whether to skip to next phrase after evaluation.
|
||||||
|
@ -247,21 +246,14 @@ list of 3 function symbols: (tuareg-symbol typerex-symbol caml-symbol)."
|
||||||
supports caml, tuareg and typerex modes by default. For other
|
supports caml, tuareg and typerex modes by default. For other
|
||||||
modes you need to set these variables:
|
modes you need to set these variables:
|
||||||
|
|
||||||
- `utop-skip-blank-and-comments'
|
- `utop-next-phrase-beginning'
|
||||||
- `utop-skip-to-end-of-phrase'
|
|
||||||
- `utop-discover-phrase'
|
- `utop-discover-phrase'
|
||||||
"
|
"
|
||||||
(symbol-name major-mode))))))
|
(symbol-name major-mode))))))
|
||||||
|
|
||||||
(defun utop-compat-skip-blank-and-comments ()
|
(defun utop-compat-next-phrase-beginning ()
|
||||||
(funcall
|
(funcall
|
||||||
(utop-compat-resolve '(tuareg-skip-blank-and-comments
|
(utop-compat-resolve '(tuareg-next-phrase
|
||||||
typerex-skip-blank-and-comments
|
|
||||||
caml-skip-blank-and-comments))))
|
|
||||||
|
|
||||||
(defun utop-compat-skip-to-end-of-phrase ()
|
|
||||||
(funcall
|
|
||||||
(utop-compat-resolve '(tuareg-skip-to-end-of-phrase
|
|
||||||
typerex-skip-to-end-of-phrase
|
typerex-skip-to-end-of-phrase
|
||||||
caml-skip-to-end-of-phrase))))
|
caml-skip-to-end-of-phrase))))
|
||||||
|
|
||||||
|
@ -844,17 +836,7 @@ If ADD-TO-HISTORY is t then the input will be added to history."
|
||||||
(defun utop-eval (start end &optional mode)
|
(defun utop-eval (start end &optional mode)
|
||||||
"Eval the given region in utop."
|
"Eval the given region in utop."
|
||||||
;; Select the text of the region
|
;; Select the text of the region
|
||||||
(let ((text
|
(utop-eval-string (buffer-substring-no-properties start end) mode))
|
||||||
(save-excursion
|
|
||||||
;; Search the start and end of the current paragraph
|
|
||||||
(goto-char start)
|
|
||||||
(funcall utop-skip-blank-and-comments)
|
|
||||||
(setq start (point))
|
|
||||||
(goto-char end)
|
|
||||||
(funcall utop-skip-to-end-of-phrase)
|
|
||||||
(setq end (point))
|
|
||||||
(buffer-substring-no-properties start end))))
|
|
||||||
(utop-eval-string text mode)))
|
|
||||||
|
|
||||||
(defun utop-eval-region (start end)
|
(defun utop-eval-region (start end)
|
||||||
"Eval the current region in utop."
|
"Eval the current region in utop."
|
||||||
|
@ -871,8 +853,9 @@ If ADD-TO-HISTORY is t then the input will be added to history."
|
||||||
(let ((pair (funcall utop-discover-phrase)))
|
(let ((pair (funcall utop-discover-phrase)))
|
||||||
(setq end (nth 2 pair))
|
(setq end (nth 2 pair))
|
||||||
(utop-eval (nth 0 pair) (nth 1 pair))))
|
(utop-eval (nth 0 pair) (nth 1 pair))))
|
||||||
(if utop-skip-after-eval-phrase
|
(when utop-skip-after-eval-phrase
|
||||||
(goto-char end))))
|
(goto-char end)
|
||||||
|
(funcall utop-next-phrase-beginning))))
|
||||||
|
|
||||||
(defun utop-eval-buffer ()
|
(defun utop-eval-buffer ()
|
||||||
"Send the buffer to utop."
|
"Send the buffer to utop."
|
||||||
|
@ -1106,7 +1089,7 @@ defaults to 0."
|
||||||
;; +-----------------------------------------------------------------+
|
;; +-----------------------------------------------------------------+
|
||||||
|
|
||||||
(defun utop-arguments ()
|
(defun utop-arguments ()
|
||||||
"Get argument list from the given command line of utop"
|
"Get argument list from the given command line of utop."
|
||||||
;; Split the command line
|
;; Split the command line
|
||||||
(let ((arguments (split-string-and-unquote utop-command)))
|
(let ((arguments (split-string-and-unquote utop-command)))
|
||||||
;; Ensure it contains at least one argument
|
;; Ensure it contains at least one argument
|
||||||
|
@ -1114,14 +1097,14 @@ defaults to 0."
|
||||||
arguments))
|
arguments))
|
||||||
|
|
||||||
(defun utop-query-arguments ()
|
(defun utop-query-arguments ()
|
||||||
"Returns the arguments of the utop command to run."
|
"Return the arguments of the utop command to run."
|
||||||
;; Read the command to run
|
;; Read the command to run
|
||||||
(when utop-edit-command
|
(when utop-edit-command
|
||||||
(setq utop-command (read-shell-command "utop command line: " utop-command))
|
(setq utop-command (read-shell-command "utop command line: " utop-command))
|
||||||
(utop-arguments)))
|
(utop-arguments)))
|
||||||
|
|
||||||
(defun utop-start (arguments)
|
(defun utop-start (arguments)
|
||||||
"Start utop."
|
"Start utop given ARGUMENTS."
|
||||||
;; Reset variables
|
;; Reset variables
|
||||||
(setq utop-prompt-min (point-max))
|
(setq utop-prompt-min (point-max))
|
||||||
(setq utop-prompt-max (point-max))
|
(setq utop-prompt-max (point-max))
|
||||||
|
|
Loading…
Reference in New Issue