Skip to content

Commit 41467d2

Browse files
committed
refactor: simplify regex patterns in help buffers
1 parent 5866d1e commit 41467d2

1 file changed

Lines changed: 49 additions & 22 deletions

File tree

pyimp.el

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -684,19 +684,29 @@ Same for the ANSI bold and normal escape sequences."
684684
end
685685
'font-lock-face 'font-lock-type-face))))
686686
(goto-char (point-min))
687-
(while
688-
(re-search-forward
689-
"^[\s]*|[\s][\s]\\(\\([_a-z][_a-z0-9]+\\)[^\n]*\\)[\n][\s]|[\s][\s][\s][\s]"
690-
nil t 1)
691-
(let* ((beg (match-beginning 1))
692-
(end (match-end 1))
693-
(beg-name (match-beginning 2))
694-
(end-name (match-end 2)))
695-
(pyimp--fontify-region beg
696-
end)
697-
(put-text-property beg-name
698-
end-name
699-
'font-lock-face 'font-lock-function-name-face)))
687+
(let ((re (rx (seq bol
688+
(zero-or-more " ")
689+
"| "
690+
(group
691+
(group
692+
(any "a-z" "_")
693+
(one-or-more
694+
(any "0-9a-z" "_")))
695+
(zero-or-more nonl))
696+
"\n | "))))
697+
(while
698+
(re-search-forward
699+
re
700+
nil t 1)
701+
(let* ((beg (match-beginning 1))
702+
(end (match-end 1))
703+
(beg-name (match-beginning 2))
704+
(end-name (match-end 2)))
705+
(pyimp--fontify-region beg
706+
end)
707+
(put-text-property beg-name
708+
end-name
709+
'font-lock-face 'font-lock-function-name-face))))
700710
(goto-char (point-min))
701711
(while (re-search-forward "^\\([a-z_][a-z0-9_]+\\)([^\n]+" nil t 1)
702712
(let* ((beg (match-beginning 0))
@@ -709,15 +719,32 @@ Same for the ANSI bold and normal escape sequences."
709719
end-name
710720
'font-lock-face 'font-lock-function-name-face)))
711721
(goto-char (point-min))
712-
(while (re-search-forward
713-
"\\(^[\s]*|[\s]*\\(Methods defined here:\\)\\|^[\s]*|[\s]*----------------------------------------------------------------------[\n][\s]*|[\s]+\\([a-z][^\n]+\\)\\)"
714-
nil t 1)
715-
(put-text-property
716-
(or (match-beginning 3)
717-
(match-beginning 2))
718-
(or (match-end 3)
719-
(match-end 2))
720-
'font-lock-face 'font-lock-keyword-face))))
722+
(let ((re (rx (group
723+
(or (seq bol
724+
(zero-or-more " ")
725+
"|"
726+
(zero-or-more " ")
727+
(group "Methods defined here:"))
728+
(seq bol
729+
(zero-or-more " ")
730+
"|"
731+
(zero-or-more " ")
732+
"----------------------------------------------------------------------\n"
733+
(zero-or-more " ")
734+
"|"
735+
(one-or-more " ")
736+
(group
737+
(any "a-z")
738+
(one-or-more nonl))))))))
739+
(while (re-search-forward
740+
re
741+
nil t 1)
742+
(put-text-property
743+
(or (match-beginning 3)
744+
(match-beginning 2))
745+
(or (match-end 3)
746+
(match-end 2))
747+
'font-lock-face 'font-lock-keyword-face)))))
721748

722749

723750

0 commit comments

Comments
 (0)