Add in-house point-in-{comment,string} predicates
Toward uncoupling Doom from smartparens.
This commit is contained in:
parent
04166d6562
commit
b332a923a5
|
@ -25,6 +25,41 @@ lines, above and below, with only whitespace in between."
|
||||||
(or (not balanced)
|
(or (not balanced)
|
||||||
(= (- pt nbeg) (- nend pt))))))))))))
|
(= (- pt nbeg) (- nend pt))))))))))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom-point-in-comment-p (&optional pos)
|
||||||
|
"Return non-nil if POS is in a comment.
|
||||||
|
|
||||||
|
POS defaults to the current position."
|
||||||
|
;; REVIEW Should we cache `syntax-ppss'?
|
||||||
|
(let* ((pos (or pos (point)))
|
||||||
|
(ppss (syntax-ppss pos)))
|
||||||
|
(or (nth 4 ppss)
|
||||||
|
(nth 8 ppss)
|
||||||
|
(and (< pos (point-max))
|
||||||
|
(memq (char-syntax (char-after pos)) '(?< ?>))
|
||||||
|
(not (eq (char-after pos) ?\n)))
|
||||||
|
(when-let (s (car (syntax-after pos)))
|
||||||
|
(or (and (/= 0 (logand (lsh 1 16) s))
|
||||||
|
(nth 4 (doom-syntax-ppss (+ pos 2))))
|
||||||
|
(and (/= 0 (logand (lsh 1 17) s))
|
||||||
|
(nth 4 (doom-syntax-ppss (+ pos 1))))
|
||||||
|
(and (/= 0 (logand (lsh 1 18) s))
|
||||||
|
(nth 4 (doom-syntax-ppss (- pos 1))))
|
||||||
|
(and (/= 0 (logand (lsh 1 19) s))
|
||||||
|
(nth 4 (doom-syntax-ppss (- pos 2)))))))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom-point-in-string-p (&optional pos)
|
||||||
|
"Return non-nil if POS is in a string."
|
||||||
|
;; REVIEW Should we cache `syntax-ppss'?
|
||||||
|
(nth 3 (syntax-ppss pos)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom-point-in-string-or-comment-p (&optional pos)
|
||||||
|
"Return non-nil if POS is in a string or comment."
|
||||||
|
(or (doom-point-in-string-p pos)
|
||||||
|
(doom-point-in-comment-p pos)))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Commands
|
;; Commands
|
||||||
|
|
Loading…
Reference in New Issue
Block a user