From e49aadc38ad7295fff40585a9295583e009b6c4d Mon Sep 17 00:00:00 2001 From: Sergey Vinokurov Date: Fri, 17 Apr 2015 00:47:09 +0300 Subject: [PATCH] use more efficient looking-at-p instead of looking-at in most places --- haskell-cabal.el | 12 ++++++------ haskell-commands.el | 4 ++-- haskell-decl-scan.el | 14 +++++++------- haskell-doc.el | 2 +- haskell-font-lock.el | 8 ++++---- haskell-indent.el | 28 ++++++++++++++-------------- haskell-indentation.el | 10 +++++----- haskell-interactive-mode.el | 4 ++-- haskell-mode.el | 18 +++++++++--------- haskell-simple-indent.el | 2 +- haskell-sort-imports.el | 8 ++++---- haskell.el | 4 ++-- 12 files changed, 57 insertions(+), 57 deletions(-) diff --git a/haskell-cabal.el b/haskell-cabal.el index c63495845..e29cf5c05 100644 --- a/haskell-cabal.el +++ b/haskell-cabal.el @@ -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 () @@ -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" diff --git a/haskell-commands.el b/haskell-commands.el index 1df28a3fb..0b9be6a7f 100644 --- a/haskell-commands.el +++ b/haskell-commands.el @@ -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)) diff --git a/haskell-decl-scan.el b/haskell-decl-scan.el index 401dd966e..b7e489332 100644 --- a/haskell-decl-scan.el +++ b/haskell-decl-scan.el @@ -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 @@ -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))))) @@ -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 @@ -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 @@ -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) diff --git a/haskell-doc.el b/haskell-doc.el index a99e57416..13932b099 100644 --- a/haskell-doc.el +++ b/haskell-doc.el @@ -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) diff --git a/haskell-font-lock.el b/haskell-font-lock.el index 417937807..8d68ad61a 100644 --- a/haskell-font-lock.el +++ b/haskell-font-lock.el @@ -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 @@ -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 diff --git a/haskell-indent.el b/haskell-indent.el index 409079b54..83f3b061e 100644 --- a/haskell-indent.el +++ b/haskell-indent.el @@ -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." @@ -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) @@ -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 "" @@ -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) @@ -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)) @@ -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) @@ -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 @@ -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)) @@ -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. @@ -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 diff --git a/haskell-indentation.el b/haskell-indentation.el index 31051cef7..71f840b58 100644 --- a/haskell-indentation.el +++ b/haskell-indentation.el @@ -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) @@ -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)) @@ -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 () @@ -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 () @@ -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))) diff --git a/haskell-interactive-mode.el b/haskell-interactive-mode.el index 8f231e1ff..81d60327d 100644 --- a/haskell-interactive-mode.el +++ b/haskell-interactive-mode.el @@ -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)) @@ -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 diff --git a/haskell-mode.el b/haskell-mode.el index cd58f23be..5b16c27c3 100644 --- a/haskell-mode.el +++ b/haskell-mode.el @@ -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. @@ -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))))) @@ -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 diff --git a/haskell-simple-indent.el b/haskell-simple-indent.el index 458417207..498e7b576 100644 --- a/haskell-simple-indent.el +++ b/haskell-simple-indent.el @@ -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? diff --git a/haskell-sort-imports.el b/haskell-sort-imports.el index 4d466322e..371f22428 100644 --- a/haskell-sort-imports.el +++ b/haskell-sort-imports.el @@ -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)))) @@ -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." @@ -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))) diff --git a/haskell.el b/haskell.el index 9d542b5f2..ba74f19ef 100644 --- a/haskell.el +++ b/haskell.el @@ -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)) @@ -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: "