Skip to content

Use more efficient looking-at-p instead of looking-at in most places #580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions haskell-cabal.el
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ OTHER-WINDOW use `find-file-other-window'."
(save-excursion
(beginning-of-line)
(cond
((looking-at haskell-cabal-subsection-header-regexp ) 'subsection-header)
((looking-at haskell-cabal-section-header-regexp) 'section-header)
((looking-at haskell-cabal-comment-regexp) 'comment)
((looking-at haskell-cabal-empty-regexp ) 'empty)
((looking-at haskell-cabal-conditional-regexp ) 'conditional)
((looking-at-p haskell-cabal-subsection-header-regexp) 'subsection-header)
((looking-at-p haskell-cabal-section-header-regexp) 'section-header)
((looking-at-p haskell-cabal-comment-regexp) 'comment)
((looking-at-p haskell-cabal-empty-regexp) 'empty)
((looking-at-p haskell-cabal-conditional-regexp ) 'conditional)
(t 'section-data))))

(defun haskell-cabal-header-p ()
Expand Down Expand Up @@ -509,7 +509,7 @@ resultung buffer-content"
"Does line only contain whitespaces and comments?"
(save-excursion
(beginning-of-line)
(looking-at "^[ \t]*\\(?:--.*\\)?$")))
(looking-at-p "^[ \t]*\\(?:--.*\\)?$")))

(defun haskell-cabal-kill-indentation ()
"Remove longest common whitespace prefix from each line"
Expand Down
4 changes: 2 additions & 2 deletions haskell-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ PROCESS."
(let ((hoogle-error (call-process "hoogle" nil t nil "search" "--exact" ident)))
(goto-char (point-min))
(unless (or (/= 0 hoogle-error)
(looking-at "^No results found")
(looking-at "^package "))
(looking-at-p "^No results found")
(looking-at-p "^package "))
(while (re-search-forward "^\\([^ ]+\\).*$" nil t)
(replace-match "\\1" nil nil))
(cl-remove-if (lambda (a) (string= "" a))
Expand Down
14 changes: 7 additions & 7 deletions haskell-decl-scan.el
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ Point is not changed."
(with-syntax-table haskell-ds-syntax-table
(if (looking-at prefix) (goto-char (match-end 0)))
;; Keyword.
(if (looking-at haskell-ds-start-keywords-re)
(if (looking-at-p haskell-ds-start-keywords-re)
nil
(or ;; Parenthesized symbolic variable.
(and (looking-at "(\\(\\s_+\\))") (match-string-no-properties 1))
;; General case.
(if (looking-at
(if (looking-at-p
(if (eq ?\( (char-after))
;; Skip paranthesised expression.
(progn
Expand Down Expand Up @@ -187,7 +187,7 @@ current line that starts with REGEXP and is not in `font-lock-comment-face'."
;; no effect on efficiency. It is probably not called enough to do
;; so.
(while (and (= (forward-line inc) 0)
(or (not (looking-at regexp))
(or (not (looking-at-p regexp))
(eq (get-text-property (point) 'face)
'font-lock-comment-face)))))

Expand Down Expand Up @@ -257,7 +257,7 @@ then point does not move if already at the start of a declaration."
;; Checking the face to ensure a declaration starts
;; here seems to be the only addition to make this
;; module support LaTeX-style literate scripts.
(if (and (looking-at start-decl-re)
(if (and (looking-at-p start-decl-re)
(not (elt (syntax-ppss) 4)))
(match-beginning 1)))))
(if (and start
Expand Down Expand Up @@ -310,7 +310,7 @@ then point does not move if already at the start of a declaration."
;; start with a declaration, move forward to start of next
;; declaration (which must exist). Otherwise, we are done.
(if (and (not direction)
(or (and (looking-at start-decl-re)
(or (and (looking-at-p start-decl-re)
(not (string= name
;; Note we must not use
;; newname here as this may
Expand All @@ -319,12 +319,12 @@ then point does not move if already at the start of a declaration."
;; of the buffer.
(haskell-ds-get-variable
line-prefix))))
(and (not (looking-at start-decl-re))
(and (not (looking-at-p start-decl-re))
(bobp))))
(haskell-ds-move-to-start-regexp-skipping-comments 1 start-decl-re)))
;; Store whether we are at the start of a declaration or not.
;; Used to calculate final result.
(let ((at-start-decl (looking-at start-decl-re)))
(let ((at-start-decl (looking-at-p start-decl-re)))
;; If we are at the beginning of a line, move over
;; line-prefix, if present at point.
(if (bolp)
Expand Down
2 changes: 1 addition & 1 deletion haskell-doc.el
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,7 @@ ToDo: Check for matching parenthesis!."
(let ((here (point)))
(goto-char here)
(skip-chars-forward " \t")
(if (looking-at "--") ; it is a comment line
(if (looking-at-p "--") ; it is a comment line
(progn
(forward-line 1)
(end-of-line)
Expand Down
8 changes: 4 additions & 4 deletions haskell-font-lock.el
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,10 @@ that should be commented under LaTeX-style literate scripts."
;; delimeters {-# .. #-}.
((save-excursion
(goto-char (nth 8 state))
(and (looking-at "{-#")
(and (looking-at-p "{-#")
(forward-comment 1)
(goto-char (- (point) 3))
(looking-at "#-}")))
(looking-at-p "#-}")))
haskell-pragma-face)
;; Haddock comment start with either "-- [|^*$]" or "{- ?[|^*$]"
;; (note space optional for nested comments and mandatory for
Expand All @@ -455,8 +455,8 @@ that should be commented under LaTeX-style literate scripts."
;; comments newline is outside of comment.
((save-excursion
(goto-char (nth 8 state))
(or (looking-at "\\(?:{- ?\\|-- \\)[|^*$]")
(and (looking-at "--") ; are we at double dash comment
(or (looking-at-p "\\(?:{- ?\\|-- \\)[|^*$]")
(and (looking-at-p "--") ; are we at double dash comment
(forward-line -1) ; this is nil on first line
(eq (get-text-property (line-end-position) 'face)
font-lock-doc-face) ; is a doc face
Expand Down
28 changes: 14 additions & 14 deletions haskell-indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ followed by an OFFSET (if present use its value otherwise use
(if (and (eq haskell-literate 'bird)
(eq (following-char) ?\>))
(forward-char 1))
(looking-at "[ \t]*$")))
(looking-at-p "[ \t]*$")))

(defun haskell-indent-back-to-indentation ()
"`back-to-indentation' function but dealing with Bird-style literate scripts."
Expand Down Expand Up @@ -311,7 +311,7 @@ It deals with both Bird style and non Bird-style scripts."
(delete-region (point) (line-beginning-position 2)))
(goto-char beg) ; Remove end.
(beginning-of-line)
(if (looking-at "\\\\begin{code}")
(if (looking-at-p "\\\\begin{code}")
(kill-line 1)))
(save-excursion ; Add the literate indication.
(goto-char end)
Expand Down Expand Up @@ -396,10 +396,10 @@ Returns the location of the start of the comment, nil otherwise."
(cond
((haskell-indent-empty-line-p) 'empty)
((haskell-indent-in-comment (point-min) (point)) 'comment)
((looking-at "\\(\\([[:alpha:]]\\(\\sw\\|'\\)*\\)\\|_\\)[ \t\n]*")
((looking-at-p "\\(\\([[:alpha:]]\\(\\sw\\|'\\)*\\)\\|_\\)[ \t\n]*")
'ident)
((looking-at "\\(|[^|]\\)[ \t\n]*") 'guard)
((looking-at "\\(=[^>=]\\|::\\|∷\\|→\\|←\\|->\\|<-\\)[ \t\n]*") 'rhs)
((looking-at-p "\\(|[^|]\\)[ \t\n]*") 'guard)
((looking-at-p "\\(=[^>=]\\|::\\|∷\\|→\\|←\\|->\\|<-\\)[ \t\n]*") 'rhs)
(t 'other)))

(defvar haskell-indent-current-line-first-ident ""
Expand Down Expand Up @@ -488,7 +488,7 @@ Returns the location of the start of the comment, nil otherwise."
"Check if there is no otherwise at GUARD."
(save-excursion
(goto-char guard)
(not (looking-at "|[ \t]*otherwise\\>"))))
(not (looking-at-p "|[ \t]*otherwise\\>"))))


(defun haskell-indent-guard (start end end-visible indent-info)
Expand Down Expand Up @@ -937,12 +937,12 @@ and find indentation info for each part."
"Return non-nil if point is in front of a `let' that has no `in'.
START is the position of the presumed `in'."
;; We're looking at either `in' or `let'.
(when (looking-at "let")
(when (looking-at-p "let")
(ignore-errors
(save-excursion
(forward-word 1)
(forward-comment (point-max))
(if (looking-at "{")
(if (looking-at-p "{")
(progn
(forward-sexp 1)
(forward-comment (point-max))
Expand Down Expand Up @@ -1001,7 +1001,7 @@ OPEN is the start position of the comment in which point is."
indent-info)))

;; We really are inside a comment.
(if (looking-at "-}")
(if (looking-at-p "-}")
(progn
(forward-char 2)
(forward-comment -1)
Expand Down Expand Up @@ -1131,7 +1131,7 @@ is at the end of an otherwise-non-empty line."

(defun haskell-indent-inside-paren (open)
;; there is an open structure to complete
(if (looking-at "\\s)\\|[;,]")
(if (looking-at-p "\\s)\\|[;,]")
;; A close-paren or a , or ; can only correspond syntactically to
;; the open-paren at `open'. So there is no ambiguity.
(progn
Expand All @@ -1150,7 +1150,7 @@ is at the end of an otherwise-non-empty line."
(let* ((end (point))
(basic-indent-info
;; Anything else than a ) is subject to layout.
(if (looking-at "\\s.\\|\\$ ")
(if (looking-at-p "\\s.\\|\\$ ")
(haskell-indent-point-to-col open) ; align a punct with (
(let ((follow (save-excursion
(goto-char (1+ open))
Expand Down Expand Up @@ -1216,14 +1216,14 @@ START if non-nil is a presumed start pos of the current definition."
;; in string?
((setq open (haskell-indent-in-string start (point)))
(list (list (+ (haskell-indent-point-to-col open)
(if (looking-at "\\\\") 0 1)))))
(if (looking-at-p "\\\\") 0 1)))))

;; in comment ?
((setq open (haskell-indent-in-comment start (point)))
(haskell-indent-comment open start))

;; Closing the declaration part of a `let' or the test exp part of a case.
((looking-at "\\(?:in\\|of\\|then\\|else\\)\\>")
((looking-at-p "\\(?:in\\|of\\|then\\|else\\)\\>")
(haskell-indent-closing-keyword start))

;; Right after a special keyword.
Expand Down Expand Up @@ -1378,7 +1378,7 @@ TYPE is either 'guard or 'rhs."
(if (<= (haskell-indent-current-indentation) defcol)
(progn
(move-to-column defcol)
(if (and (looking-at defname) ; start of equation
(if (and (looking-at-p defname) ; start of equation
(not (haskell-indent-open-structure start-block (point))))
(push (cons (point) 'eqn) eqns-start)
;; found a less indented point not starting an equation
Expand Down
10 changes: 5 additions & 5 deletions haskell-indentation.el
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ the current buffer."
(goto-char ps)
(beginning-of-line)))
(when (and (>= 2 (haskell-indentation-current-indentation))
(not (looking-at ">\\s-*$")))
(not (looking-at-p ">\\s-*$")))
(forward-char 2)
(throw 'return nil))
(when (bobp)
Expand Down Expand Up @@ -656,7 +656,7 @@ the current buffer."
(defun haskell-indentation-declaration-layout ()
(haskell-indentation-layout #'haskell-indentation-declaration))

;; a layout list with case expressions
;; a layout list with case expressions
(defun haskell-indentation-case-layout ()
(haskell-indentation-layout #'haskell-indentation-case))

Expand Down Expand Up @@ -905,7 +905,7 @@ the current buffer."
(throw 'parse-end nil))

;; after an 'open' expression such as 'if', exit
(unless (member (car parser) '("(" "[" "{" "do" "case"))
(unless (member (car parser) '("(" "[" "{" "do" "case"))
(throw 'return nil)))))))))

(defun haskell-indentation-test-indentations ()
Expand Down Expand Up @@ -961,7 +961,7 @@ the current buffer."
;; and current-indent after the separator
;; For example:
;; l = [ 1
;; , 2
;; , 2
;; , -- start now here

(defun haskell-indentation-at-separator ()
Expand Down Expand Up @@ -1174,7 +1174,7 @@ the current buffer."
((looking-at "\\(→\\|←\\|∷\\)\\([^-:!#$%&*+./<=>?@\\\\^|~]\\|$\\)")
(let ((tok (match-string-no-properties 1)))
(or (cdr (assoc tok haskell-indentation-unicode-tokens)) tok)))
((looking-at"[-:!#$%&*+./<=>?@\\\\^|~`]" )
((looking-at-p "[-:!#$%&*+./<=>?@\\\\^|~`]")
'operator)
(t 'value)))

Expand Down
4 changes: 2 additions & 2 deletions haskell-interactive-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ FILE-NAME only."
(let ((msg-file-name (match-string-no-properties 1))
(msg-startpos (line-beginning-position)))
;; skip over hanging continuation message lines
(while (progn (forward-line) (looking-at "^[ ]+")))
(while (progn (forward-line) (looking-at-p "^[ ]+")))

(when (or (not file-name) (string= file-name msg-file-name))
(let ((inhibit-read-only t))
Expand Down Expand Up @@ -656,7 +656,7 @@ FILE-NAME only."
(haskell-interactive-mode-error-forward))

(setq reset-locus t)
(unless (looking-at haskell-interactive-mode-error-regexp)
(unless (looking-at-p haskell-interactive-mode-error-regexp)
(error "no errors found")))

;; move point if needed
Expand Down
18 changes: 9 additions & 9 deletions haskell-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,12 @@ May return a qualified name."
;; If we're looking at a module ID that qualifies further IDs, add
;; those IDs.
(goto-char start)
(while (and (looking-at "[[:upper:]]") (eq (char-after end) ?.)
(while (and (looking-at-p "[[:upper:]]") (eq (char-after end) ?.)
;; It's a module ID that qualifies further IDs.
(goto-char (1+ end))
(save-excursion
(when (not (zerop (skip-syntax-forward
(if (looking-at "\\s_") "_" "w'"))))
(if (looking-at-p "\\s_") "_" "w'"))))
(setq end (point))))))
;; If we're looking at an ID that's itself qualified by previous
;; module IDs, add those too.
Expand All @@ -533,7 +533,7 @@ May return a qualified name."
(progn (forward-char -1)
(not (zerop (skip-syntax-backward "w'"))))
(skip-syntax-forward "'")
(looking-at "[[:upper:]]"))
(looking-at-p "[[:upper:]]"))
(setq start (point)))
;; This is it.
(cons start end)))))
Expand Down Expand Up @@ -965,14 +965,14 @@ LOC = (list FILE LINE COL)"
(defun haskell-mode-insert-scc-at-point ()
"Insert an SCC annotation at point."
(interactive)
(if (or (looking-at "\\b\\|[ \t]\\|$") (and (not (bolp))
(save-excursion
(forward-char -1)
(looking-at "\\b\\|[ \t]"))))
(let ((space-at-point (looking-at "[ \t]")))
(if (or (looking-at-p "\\b\\|[ \t]\\|$") (and (not (bolp))
(save-excursion
(forward-char -1)
(looking-at-p "\\b\\|[ \t]"))))
(let ((space-at-point (looking-at-p "[ \t]")))
(unless (and (not (bolp)) (save-excursion
(forward-char -1)
(looking-at "[ \t]")))
(looking-at-p "[ \t]")))
(insert " "))
(insert "{-# SCC \"\" #-}")
(unless space-at-point
Expand Down
2 changes: 1 addition & 1 deletion haskell-simple-indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ point beyond the current column, position given by
(not (zerop invisible-from)))
(zerop (forward-line -1)))
;; Ignore empty lines.
(if (not (looking-at "[ \t]*\n"))
(if (not (looking-at-p "[ \t]*\n"))
(let ((this-indentation (current-indentation)))
;; Is this line so indented that it cannot have
;; influence on indentation points?
Expand Down
8 changes: 4 additions & 4 deletions haskell-sort-imports.el
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ within that region."

(defun haskell-sort-imports-collect-imports ()
(let ((imports (list)))
(while (looking-at "import")
(while (looking-at-p "import")
(let* ((points (haskell-sort-imports-decl-points))
(string (buffer-substring-no-properties (car points)
(cdr points))))
Expand All @@ -96,7 +96,7 @@ within that region."
"Are we at an import?"
(save-excursion
(haskell-sort-imports-goto-import-start)
(looking-at "import")))
(looking-at-p "import")))

(defun haskell-sort-imports-goto-import-start ()
"Go to the start of the import."
Expand All @@ -107,8 +107,8 @@ within that region."
(save-excursion
(let ((start (or (progn (goto-char (line-end-position))
(search-backward-regexp "^[^ \n]" nil t 1)
(unless (or (looking-at "^-}$")
(looking-at "^{-$"))
(unless (or (looking-at-p "^-}$")
(looking-at-p "^{-$"))
(point)))
0))
(end (progn (goto-char (1+ (point)))
Expand Down
4 changes: 2 additions & 2 deletions haskell.el
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
(interactive)
(with-current-buffer (haskell-session-interactive-buffer (haskell-session))
(if (progn (goto-char (line-beginning-position))
(looking-at haskell-interactive-mode-error-regexp))
(looking-at-p haskell-interactive-mode-error-regexp))
(progn (forward-line -1)
(haskell-interactive-jump-to-error-line))
(progn (goto-char (point-max))
Expand All @@ -268,7 +268,7 @@
(self-insert-command 1)
(cond ((and haskell-mode-contextual-import-completion
(save-excursion (forward-word -1)
(looking-at "^import$")))
(looking-at-p "^import$")))
(insert " ")
(let ((module (haskell-complete-module-read
"Module: "
Expand Down