-
Notifications
You must be signed in to change notification settings - Fork 349
Bunch of minor updates to decl-scan module. #1456
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
Changes from all commits
53e51fe
64a1112
031856b
9d049bc
8103e59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,17 +194,18 @@ 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 "> ?" | ||
"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 | ||
|
@@ -217,10 +218,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, | ||
|
@@ -356,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 | ||
|
@@ -382,18 +378,17 @@ there." | |
nil)) | ||
|
||
(defun haskell-ds-line-commented-p () | ||
"Tests 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)) | ||
"Test if all characters from `point' to `end-of-line' pass `haskell-ds-comment-p'." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is horrible. The way to find end of current comment is to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only usage of this function is to go back to the end of a definition. That requires going through all lines that are composed only of white space and comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
(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 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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't add comment on a line that follows, so I'm putting it here: comments in haskell have structure and we use more faces than just
font-lock-comment-face
:haskell-pragma-face
,haskell-liquid-haskell-annotation-face
,haskell-literate-comment-face
. Sometimes we also add(:weight bold)
and(:slant italic)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The weight and slant already work. I can add these other faces to the member test if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they have to be there. Otherwise declscan will not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the help.