From 53e51fe3b265b5e4d06ceaba575299edc29fc4f5 Mon Sep 17 00:00:00 2001 From: Czipperz Date: Mon, 14 Nov 2016 15:22:01 -0800 Subject: [PATCH 1/5] Update documentation --- haskell-decl-scan.el | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/haskell-decl-scan.el b/haskell-decl-scan.el index 75da0a9d6..71b5df823 100644 --- a/haskell-decl-scan.el +++ b/haskell-decl-scan.el @@ -194,8 +194,7 @@ current line that starts with REGEXP and is not in `font-lock-comment-face'." 'font-lock-comment-face))))) (defun haskell-ds-move-to-start-regexp-skipping-comments (inc regexp) - "Like haskell-ds-move-to-start-regexp, but uses syntax-ppss to - skip comments" + "Like haskell-ds-move-to-start-regexp, but uses syntax-ppss to skip comments." (let (p) (cl-loop do (setq p (point)) @@ -205,6 +204,7 @@ current line that starts with REGEXP and is not in `font-lock-comment-face'." (defvar literate-haskell-ds-line-prefix "> ?" "Regexp matching start of a line of Bird-style literate code. + Current value is \"> \" as we assume top-level declarations start at column 3. Must not contain the special \"^\" regexp as we may not use the regexp at the start of a regexp string. Note this is @@ -382,8 +382,7 @@ there." nil)) (defun haskell-ds-line-commented-p () - "Tests if all characters from `point' to `end-of-line' pass -`haskell-ds-comment-p'" + "Test if all characters from `point' to `end-of-line' pass `haskell-ds-comment-p'." (let ((r t)) (while (and r (not (eolp))) (if (not (haskell-ds-comment-p)) @@ -392,8 +391,7 @@ there." r)) (defun haskell-ds-forward-decl () - "Move forward to the first character that starts a top-level -declaration. As `haskell-ds-backward-decl' but forward." + "Move forward to the end of the top-level declaration." (interactive) (let ((p (point)) b e empty was-at-bob) ;; Go back to beginning of defun, then go to beginning of next From 64a111266f7ce2c53f635bf1187a9513efa92764 Mon Sep 17 00:00:00 2001 From: Czipperz Date: Mon, 14 Nov 2016 15:38:55 -0800 Subject: [PATCH 2/5] Fix `haskell-ds-whitespace-p` --- haskell-decl-scan.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/haskell-decl-scan.el b/haskell-decl-scan.el index 71b5df823..2028d2346 100644 --- a/haskell-decl-scan.el +++ b/haskell-decl-scan.el @@ -217,10 +217,10 @@ only for `imenu' support.") (concat literate-haskell-ds-line-prefix haskell-ds-start-decl-re) "The regexp that starts a Bird-style literate Haskell declaration.") -(defun haskell-ds-whitespace-p (char) - "Test if CHAR is a whitespace character." - ;; the nil is a bob/eob test - (member char '(nil ?\t ?\n ?\ ))) +(defun haskell-ds-whitespace-p () + "Test if PT is at a whitespace character." + (or (eolp) + (equal (string-to-syntax " ") (syntax-after (point))))) (defun haskell-ds-move-to-decl (direction bird-literate fix) "General function for moving to the start of a declaration, From 031856bae1d79891ca5d3af1597df001c5893ccb Mon Sep 17 00:00:00 2001 From: Czipperz Date: Mon, 14 Nov 2016 15:45:56 -0800 Subject: [PATCH 3/5] Skipping comments skips their open/close delimiters as well --- haskell-decl-scan.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/haskell-decl-scan.el b/haskell-decl-scan.el index 2028d2346..554150fa4 100644 --- a/haskell-decl-scan.el +++ b/haskell-decl-scan.el @@ -194,12 +194,13 @@ current line that starts with REGEXP and is not in `font-lock-comment-face'." 'font-lock-comment-face))))) (defun haskell-ds-move-to-start-regexp-skipping-comments (inc regexp) - "Like haskell-ds-move-to-start-regexp, but uses syntax-ppss to skip comments." + "Like haskell-ds-move-to-start-regexp, but skips comments." (let (p) (cl-loop do (setq p (point)) (haskell-ds-move-to-start-regexp inc regexp) - while (and (nth 4 (syntax-ppss)) + while (and (not (haskell-ds-whitespace-p)) + (haskell-ds-comment-p) (/= p (point)))))) (defvar literate-haskell-ds-line-prefix "> ?" From 9d049bc025b405943df827f8e71d330ad0dcfb75 Mon Sep 17 00:00:00 2001 From: Czipperz Date: Mon, 14 Nov 2016 15:48:27 -0800 Subject: [PATCH 4/5] `haskell-ds-comment-p` only works on current point. It was never used with the optional custom point, so just removed it. There was also a bug where the custom point wasn't even being used, that this fixed. --- haskell-decl-scan.el | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/haskell-decl-scan.el b/haskell-decl-scan.el index 554150fa4..8bf3fe376 100644 --- a/haskell-decl-scan.el +++ b/haskell-decl-scan.el @@ -357,20 +357,15 @@ there." (interactive) (haskell-ds-move-to-decl nil (haskell-ds-bird-p) nil)) -(defun haskell-ds-comment-p - (&optional - pt) - "Test if the cursor is on whitespace or a comment. - -`PT' defaults to `(point)'" +(defun haskell-ds-comment-p () + "Test if the cursor is on whitespace or a comment." ;; ensure result is `t' or `nil' instead of just truthy (if (or ;; is cursor on whitespace - (haskell-ds-whitespace-p (following-char)) + (haskell-ds-whitespace-p) ;; http://emacs.stackexchange.com/questions/14269/how-to-detect-if-the-point-is-within-a-comment-area ;; is cursor at begging, inside, or end of comment - (let ((fontfaces (get-text-property (or pt - (point)) 'face))) + (let ((fontfaces (get-text-property (point) 'face))) (when (not (listp fontfaces)) (setf fontfaces (list fontfaces))) (delq nil (mapcar From 8103e59dfee19ae3e468f3a7447211f6ed0644b6 Mon Sep 17 00:00:00 2001 From: Czipperz Date: Mon, 14 Nov 2016 15:59:23 -0800 Subject: [PATCH 5/5] `haskell-ds-line-commented-p` no longer moves point. --- haskell-decl-scan.el | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/haskell-decl-scan.el b/haskell-decl-scan.el index 8bf3fe376..c63ff248b 100644 --- a/haskell-decl-scan.el +++ b/haskell-decl-scan.el @@ -379,12 +379,13 @@ there." (defun haskell-ds-line-commented-p () "Test if all characters from `point' to `end-of-line' pass `haskell-ds-comment-p'." - (let ((r t)) - (while (and r (not (eolp))) - (if (not (haskell-ds-comment-p)) - (setq r nil)) - (forward-char)) - r)) + (save-excursion + (let ((r t)) + (while (and r (not (eolp))) + (if (not (haskell-ds-comment-p)) + (setq r nil)) + (forward-char)) + r))) (defun haskell-ds-forward-decl () "Move forward to the end of the top-level declaration."