Skip to content

Commit

Permalink
Prevent infloops on blanks travelling
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Nov 23, 2015
1 parent e42371a commit b1911a3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
31 changes: 18 additions & 13 deletions lisp/ess-r-syntax.el
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,13 @@ return the prefix."
into account."
(when (ess-skip-blanks-backward-1)
(prog1 t
(when newlines
(while (= (point) (line-beginning-position))
(forward-line -1)
(goto-char (line-end-position))
(ess-climb-comment)
(ess-skip-blanks-backward-1))))))
(while (and newlines
(/= (point) (point-min))
(= (point) (line-beginning-position)))
(forward-line -1)
(goto-char (line-end-position))
(ess-climb-comment)
(ess-skip-blanks-backward-1)))))

(defun ess-skip-blanks-backward-1 ()
(and (/= (point) (point-min))
Expand All @@ -203,13 +204,17 @@ into account."
(defun ess-skip-blanks-forward (&optional newlines)
"Skip blanks and newlines forward, taking end-of-line comments
into account."
(when (skip-chars-forward " \t")
(prog1 t
(when newlines
(while (= (point) (ess-code-end-position))
(forward-line)
(ess-back-to-indentation)
(skip-chars-forward " \t"))))))
(ess-any ((/= 0 (skip-chars-forward " \t")))
((ess-while (and newlines
(= (point) (ess-code-end-position))
(when (ess-save-excursion-when-nil
;; Handles corner cases such as point being on last line
(let ((orig-point (point)))
(forward-line)
(ess-back-to-indentation)
(> (point) orig-point)))
(skip-chars-forward " \t")
t))))))

(defun ess-jump-char (char)
(ess-save-excursion-when-nil
Expand Down
2 changes: 1 addition & 1 deletion test/generate-literate-cases
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

(mapc (lambda (file)
(ess-ltest-R (expand-file-name file ess-literate-path)))
'("roxy.R" "code-fill.R" "misc.R"))
'("roxy.R" "code-fill.R" "misc.R" "syntax.R"))
27 changes: 27 additions & 0 deletions test/literate/syntax.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

##### Blanks, Characters and Comments

### 1 ----------------------------------------------------------------

text
text

##! (ess-skip-blanks-forward t)

text
text


### 2 ----------------------------------------------------------------

text# comment

##! (when (not (ess-skip-blanks-forward t))
##! (insert "failure"))

text# comment

##> (when (ess-skip-blanks-forward t)
##> (insert "failure"))

text# comment

0 comments on commit b1911a3

Please sign in to comment.