branch: externals/sql-indent
commit c94dd1fbe1bad2367733c14a8a163502f8937e00
Author: Alex Harsányi <[email protected]>
Commit: GitHub <[email protected]>
Performance improvements (#31)
* Establish a limit for syntactic information search
See also issue #26
`sqlind-syntax-of-line' will use `sqlind-begining-of-directive' to
establish a
search limit for the current syntax. This avoids calling
`sqlind-begining-of-directive' repeatedly.
This changes the indentation anchor for toplevel statements when directives
are present in the file. Unit test data updated accordingly.
* sql-indent.el (sqlind-search-limit): new variable
(sqlind-beginning-of-statement-1): avoid searching before
`sqlind-search-limit'
(sqlind-beginning-of-statement): use `sqlind-search-limit'
(sqlind-maybe-loop-statement): fix mispelling of throw symbol
(sqlind-beginning-of-block): limit search to `sqlind-search-limit'
(sqlind-syntax-of-line): bind `sqlind-search-limit' to
`sqlind-begining-of-directive'
* Fix spelling of `sqlind-beginning-of-directive`
---
sql-indent.el | 20 ++++++++++++--------
test-data/pr17-syn.eld | 48 ++++++++++++++++++++++++------------------------
test-data/pr18-syn.eld | 18 +++++++++---------
test-data/pr24-syn.eld | 34 +++++++++++++++++-----------------
4 files changed, 62 insertions(+), 58 deletions(-)
diff --git a/sql-indent.el b/sql-indent.el
index 0a1ec3e..3857038 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -273,7 +273,7 @@ determine the statement start in SQLite scripts.")
"\\>")
"Match an MS SQL Sever directive at the beginning of a line.")
-(defun sqlind-begining-of-directive ()
+(defun sqlind-beginning-of-directive ()
"Return the position of an SQL directive, or nil.
We will never move past one of these in our scan. We also assume
they are one-line only directives."
@@ -288,12 +288,16 @@ they are one-line only directives."
(forward-line 1)
(point))))))
+(defvar sqlind-search-limit nil
+ "Limit of search when looking for syntactic elements.
+This variable is dynamically bound.")
+
(defun sqlind-beginning-of-statement-1 (limit)
"Return the position of a block start, or nil.
But don't go before LIMIT."
(save-excursion
(catch 'done
- (while (not (eq (point) (or limit (point-min))))
+ (while (> (point) (or limit (point-min)))
(when (re-search-backward
";\\|:=\\|\\b\\(declare\\|begin\\|cursor\\|loop\\|if\\|then\\|else\\|elsif\\)\\b\\|)"
limit 'noerror)
@@ -337,10 +341,9 @@ But don't go before LIMIT."
(when (> (nth 0 ppss) 0)
(nth 1 ppss)))
;; Look for an ordinary statement start
- (let ((directive-start (sqlind-begining-of-directive)))
- (or (sqlind-beginning-of-statement-1 directive-start)
- ;; Fall back on the directive position...
- directive-start))
+ (or (sqlind-beginning-of-statement-1 sqlind-search-limit)
+ ;; Fall back on the search limit
+ sqlind-search-limit)
;; ... or point-min
(point-min)))
@@ -524,7 +527,7 @@ See also `sqlind-beginning-of-block'"
(pop sqlind-end-stmt-stack)
(unless (and (eq kind 'loop)
(sqlind-labels-match label loop-label))
- (throw 'finshed
+ (throw 'finished
(list 'syntax-error
"bad closing for loop block" (point)
pos)))))))))))
@@ -726,7 +729,7 @@ reverse order (a stack) and is used to skip over nested
blocks."
(interactive)
(catch 'finished
(let ((sqlind-end-stmt-stack end-statement-stack))
- (while (re-search-backward sqlind-start-block-regexp nil 'noerror)
+ (while (re-search-backward sqlind-start-block-regexp sqlind-search-limit
'noerror)
(or (sqlind-in-comment-or-string (point))
(when (looking-at ")") (forward-char 1) (forward-sexp -1) t)
(sqlind-maybe-end-statement)
@@ -1352,6 +1355,7 @@ procedure block."
(save-excursion
(with-syntax-table sqlind-syntax-table
(let* ((pos (progn (back-to-indentation) (point)))
+ (sqlind-search-limit (sqlind-beginning-of-directive))
(context-start (progn (sqlind-beginning-of-statement) (point)))
(context (list (cons 'statement-continuation context-start)))
(have-block-context nil))
diff --git a/test-data/pr17-syn.eld b/test-data/pr17-syn.eld
index 6530fdc..ce23662 100644
--- a/test-data/pr17-syn.eld
+++ b/test-data/pr17-syn.eld
@@ -1,13 +1,13 @@
(((toplevel . 1))
- ((toplevel . 1))
- ((comment-start . 1)
- (toplevel . 1))
- ((comment-start . 1)
- (toplevel . 1))
- ((toplevel . 1))
- ((toplevel . 1))
- ((toplevel . 1))
- ((toplevel . 1))
+ ((toplevel . 15))
+ ((comment-start . 33)
+ (toplevel . 33))
+ ((comment-start . 33)
+ (toplevel . 33))
+ ((toplevel . 33))
+ ((toplevel . 33))
+ ((toplevel . 33))
+ ((toplevel . 33))
((select-column-continuation . 99)
(statement-continuation . 99))
((select-column-continuation . 99)
@@ -28,8 +28,8 @@
(((in-select-clause "where")
. 306)
(statement-continuation . 99))
- ((toplevel . 1))
- ((toplevel . 1))
+ ((toplevel . 33))
+ ((toplevel . 33))
((select-column . 375)
(statement-continuation . 375))
((select-column . 375)
@@ -98,8 +98,8 @@
(((in-select-clause "where")
. 624)
(statement-continuation . 375))
- ((toplevel . 1))
- ((toplevel . 1))
+ ((toplevel . 33))
+ ((toplevel . 33))
((delete-clause . 1417)
(statement-continuation . 1417))
(((in-delete-clause "where")
@@ -113,8 +113,8 @@
(((in-delete-clause "where")
. 1442)
(statement-continuation . 1417))
- ((toplevel . 1))
- ((toplevel . 1))
+ ((toplevel . 33))
+ ((toplevel . 33))
((update-clause . 1576)
(statement-continuation . 1576))
(((in-update-clause "set")
@@ -133,8 +133,8 @@
(((in-update-clause "where")
. 1674)
(statement-continuation . 1576))
- ((toplevel . 1))
- ((toplevel . 1))
+ ((toplevel . 33))
+ ((toplevel . 33))
(((in-insert-clause "insert into")
. 1800)
(statement-continuation . 1800))
@@ -205,10 +205,10 @@
(((in-select-clause "order by")
. 2798)
(statement-continuation . 1800))
- ((comment-start . 1)
- (toplevel . 1))
- ((comment-start . 1)
- (toplevel . 1))
- ((comment-start . 1)
- (toplevel . 1))
- ((toplevel . 1)))
\ No newline at end of file
+ ((comment-start . 33)
+ (toplevel . 33))
+ ((comment-start . 33)
+ (toplevel . 33))
+ ((comment-start . 33)
+ (toplevel . 33))
+ ((toplevel . 33)))
\ No newline at end of file
diff --git a/test-data/pr18-syn.eld b/test-data/pr18-syn.eld
index 3b45d7a..6a7601f 100644
--- a/test-data/pr18-syn.eld
+++ b/test-data/pr18-syn.eld
@@ -1,5 +1,5 @@
(((toplevel . 1))
- ((toplevel . 1))
+ ((toplevel . 21))
((declare-statement . 21))
((declare-statement . 21))
(((block-start begin)
@@ -56,13 +56,13 @@
. 78)
((in-begin-block toplevel-block "")
. 78))
- ((toplevel . 1))
- ((comment-start . 1)
- (toplevel . 1))
- ((comment-start . 1)
- (toplevel . 1))
- ((comment-start . 1)
- (toplevel . 1))
- ((toplevel . 1)))
+ ((toplevel . 21))
+ ((comment-start . 21)
+ (toplevel . 21))
+ ((comment-start . 21)
+ (toplevel . 21))
+ ((comment-start . 21)
+ (toplevel . 21))
+ ((toplevel . 21)))
\ No newline at end of file
diff --git a/test-data/pr24-syn.eld b/test-data/pr24-syn.eld
index a38437c..b1b7171 100644
--- a/test-data/pr24-syn.eld
+++ b/test-data/pr24-syn.eld
@@ -1,7 +1,7 @@
(((toplevel . 1))
- ((toplevel . 1))
- ((toplevel . 1))
- ((toplevel . 1))
+ ((toplevel . 21))
+ ((toplevel . 49))
+ ((toplevel . 49))
((declare-statement . 50))
((declare-statement . 50))
(((block-start begin)
@@ -61,17 +61,17 @@
. 106)
((in-begin-block toplevel-block "")
. 106))
- ((toplevel . 1))
- ((comment-start . 1)
- (toplevel . 1))
- ((comment-start . 1)
- (toplevel . 1))
- ((comment-start . 1)
- (toplevel . 1))
- ((comment-start . 1)
- (toplevel . 1))
- ((comment-start . 1)
- (toplevel . 1))
- ((comment-start . 1)
- (toplevel . 1))
- ((toplevel . 1)))
\ No newline at end of file
+ ((toplevel . 49))
+ ((comment-start . 49)
+ (toplevel . 49))
+ ((comment-start . 49)
+ (toplevel . 49))
+ ((comment-start . 49)
+ (toplevel . 49))
+ ((comment-start . 49)
+ (toplevel . 49))
+ ((comment-start . 49)
+ (toplevel . 49))
+ ((comment-start . 49)
+ (toplevel . 49))
+ ((toplevel . 49)))
\ No newline at end of file