branch: externals/smalltalk-mode commit 098430e1146cd761f7069312a0f00a9b83246d3c Author: Stefan Monnier <monn...@iro.umontreal.ca> Commit: Stefan Monnier <monn...@iro.umontreal.ca>
* smalltalk-mode.el: Fix defun forward motion and for bang syntax (smalltalk--goto-defun-start): Rename from smalltalk-goto-defun-start. Take an arg to know whether we're moving forward or backward. Implement forward search. Add support for bang syntax. (smalltalk-goto-defun-end): Rename from smalltalk-goto-defun-end. Add support for bang syntax. --- smalltalk-mode.el | 69 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/smalltalk-mode.el b/smalltalk-mode.el index ed9e45c..988d38e 100644 --- a/smalltalk-mode.el +++ b/smalltalk-mode.el @@ -31,6 +31,8 @@ ;; - Syntax-aware navigation. ;; - Code templates. ;; - Interacting with an Smalltalk REPL from within the source code. +;; - Support for prettify-symbols-mode. +;; - defun navigation. ;;; Old History: @@ -267,28 +269,51 @@ Also matches the assignment operator (in submatch 1).") (string-to-syntax "."))))))) ))) -(defun smalltalk-goto-defun-start () - "Move backward to the beginning of a defun. +(defun smalltalk--goto-defun-start (arg) + "Move to the beginning of a defun. If search is successful, return t; point ends up at the beginning -of the line where the search succeeded. Otherwise, return nil. -FIXME: This version assumes gst3 syntax" - (while (progn - (while (progn ;; to ignote string/comment - (search-backward "[") - (nth 8 (syntax-ppss)))) - (smalltalk--smie-exp-p))) ;; is it an exp or method body? - (when (looking-at "\\[") - (smalltalk--smie-begin-def))) - -(defun smalltalk-goto-defun-end () - "Move forward to next end of defun. - FIXME: This version assumes gst3 syntax" - (while (progn ;; to ignote string/comment - (search-forward "[") - (nth 8 (syntax-ppss)))) - (backward-char 1) - (forward-sexp)) +of the line where the search succeeded. Otherwise, return nil." + (if (< arg 0) + (progn + (while (and + (re-search-forward "[[!]" nil 'move) + (or (nth 8 (syntax-ppss)) ;False positive within string/comment. + (and (eq (char-before) ?\[) + ;; Check if it's a defun or a mere block. + (save-excursion + (forward-char -1) + (smalltalk--smie-exp-p))) + (< (setq arg (1+ arg)) 0) ;Skip N times. + ))) + (forward-char -1)) + (forward-comment (- (point))) + (if (eq (char-before) ?!) (forward-char -1)) + (while (and + (re-search-backward "[[!]" nil 'move) + (or (nth 8 (syntax-ppss)) ;False positive within string/comment. + (and (eq (char-after) ?\[) + (smalltalk--smie-exp-p)) ;Not a defun but a mere block. + (> (setq arg (1- arg)) 0) ;Skip N times. + )))) + (pcase (char-after) + (`?\[ (smalltalk--smie-begin-def)) + (`?! (forward-char 1) + (forward-comment (point-max))))) + +(defun smalltalk--goto-defun-end () + "Move forward to end of defun at point." + ;; We can presume that we're at position returned by + ;; `smalltalk--goto-defun-start'. + (let ((pos (point))) + (forward-comment (- (point))) + (if (eq (char-before) ?!) + (smie-forward-sexp "!") + (goto-char pos) + (while (and (search-forward "[" nil t) + (nth 8 (syntax-ppss)))) ;; ignote string/comment + (backward-char 1) + (forward-sexp)))) ;;;; ---[ SMIE support ]------------------------------------------------ @@ -555,9 +580,9 @@ Commands: (set (make-local-variable 'syntax-propertize-function) smalltalk--syntax-propertize) (set (make-local-variable 'beginning-of-defun-function) - #'smalltalk-goto-defun-start) + #'smalltalk--goto-defun-start) (set (make-local-variable 'end-of-defun-function) - #'smalltalk-goto-defun-end) + #'smalltalk--goto-defun-end) ;; font-locking (set (make-local-variable 'font-lock-defaults) '((smalltalk-font-lock-keywords