branch: elpa/j-mode commit 67eb25767dfe8606ecde72d3744e073077ea2714 Author: LdBeth <andp...@foxmail.com> Commit: LdBeth <andp...@foxmail.com>
Refactored j-help; Updated comment font lock interaction --- j-font-lock.el | 13 +++++++--- j-help.el | 78 +++++++++++++++++++++++++--------------------------------- j-mode.el | 6 ++--- 3 files changed, 44 insertions(+), 53 deletions(-) diff --git a/j-font-lock.el b/j-font-lock.el index 4ecfb576fe..dd98458a3f 100644 --- a/j-font-lock.el +++ b/j-font-lock.el @@ -91,14 +91,15 @@ (modify-syntax-entry ?\' "." table) ;; (modify-syntax-entry ?N "w 1" table) ;; (modify-syntax-entry ?B "w 2" table) - (modify-syntax-entry ?\n ">" table) + ;; (modify-syntax-entry ?\n ">" table) ;; (modify-syntax-entry ?\r ">" table) table) "Syntax table for j-mode") (defalias 'j-mode-syntax-propertize (syntax-propertize-rules - ("\\(N\\)\\(B\\)\\." (1 "w 1") (2 "w 2")) + ("\\(N\\)\\(B\\)\\..*$" (1 "w 1") (2 "w 2") + (0 (j-font-lock-nota-bene))) ("\\(?:0\\|noun\\)\s+\\(?::\s*0\\|define\\)" (0 (j-font-lock-multiline-string ?:))) ("^\\()\\)" (1 (j-font-lock-multiline-string ?\)))) @@ -108,12 +109,16 @@ ("\\('\\)`?[0-9A-Z_a-z ]*\\('\\)\s*=[.:]" (1 ".") (2 ".")) ("\\('\\)\\(?:[^'\n]\\|''\\)*\\('\\)" (1 "\"") (2 "\"")))) +(defun j-font-lock-nota-bene () + (let ((eol (pos-eol))) + (put-text-property (1- eol) eol + 'syntax-table (string-to-syntax ">")))) (defun j-font-lock-multiline-string (arg) (pcase arg - (?: (let* ((ppss (save-excursion (backward-char 2) (syntax-ppss))) + (?: (let* ((ppss (syntax-ppss)) (string-start (and (eq t (nth 3 ppss)) (nth 8 ppss))) (eol (pos-eol))) - (unless string-start + (unless (or string-start (> (1+ eol) (point-max))) (put-text-property eol (1+ eol) 'syntax-table (string-to-syntax "|"))) nil)) diff --git a/j-help.el b/j-help.el index 77898f0eda..58362c57a6 100644 --- a/j-help.el +++ b/j-help.el @@ -2,7 +2,7 @@ ;;; j-help.el --- Documentation extention for j-mode ;; Copyright (C) 2012 Zachary Elliott -;; Copyright (C) 2023 LdBeth +;; Copyright (C) 2023, 2024 LdBeth ;; ;; Authors: Zachary Elliott <zacharyellio...@gmail.com> ;; URL: http://github.com/ldbeth/j-mode @@ -43,28 +43,21 @@ ;;; Code: -(defun group-by* ( list fn prev coll agr ) - "Helper method for the group-by function. Should not be called directly." - (if list - (let* ((head (car list)) - (tail (cdr list))) - (if (eql (funcall fn head) (funcall fn prev)) - (group-by* tail fn head (cons head coll) agr) - (group-by* tail fn head '() (cons coll agr)))) - (cons coll agr))) - -(defun group-by ( list fn ) - "Group-by is a FUNCTION across LIST, returning a sequence -It groups the objects in LIST according to the predicate FN" - (let ((sl (sort list (lambda (x y) (< (funcall fn x) (funcall fn y)))))) - (group-by* sl fn '() '() '()))) - -(defun j-some ( fn list ) - (let (val) - (while (and list (not val)) - (setq val (funcall fn (car list)) - list (cdr list))) - val)) +(defun j-help--process-voc-list (alist) + (let ((table (make-hash-table)) + res) + (dolist (x alist) + (let ((len (length (car x)))) + (puthash len + (cons x (gethash len table)) + table))) + (maphash (lambda (key l) (push + (list key + (regexp-opt (mapcar #'car l)) + l) + res)) + table) + res)) (defgroup j-help nil "Documentation extention for j-mode" @@ -119,11 +112,7 @@ It groups the objects in LIST according to the predicate FN" "(string * string) alist") (defconst j-help-dictionary-data-block - (mapcar - (lambda (l) (list (length (caar l)) - (regexp-opt (mapcar #'car l)) - l)) - (delq nil (group-by j-help-voc-alist (lambda (x) (length (car x)))))) + (j-help--process-voc-list j-help-voc-alist) "(int * string * (string * string) alist) list") (defun j-help-valid-dictionary () @@ -136,7 +125,6 @@ It groups the objects in LIST according to the predicate FN" j-help-remote-dictionary-url)))) (defun j-help-symbol-pair-to-doc-url ( alist-data ) - "" (let ((dic (j-help-valid-dictionary))) (if (or (not alist-data) (string= dic "")) (error "%s" "No dictionary found. Please specify a dictionary.") @@ -148,21 +136,23 @@ It groups the objects in LIST according to the predicate FN" "Convert J-SYMBOL into localtion URL" (j-help-symbol-pair-to-doc-url (assoc j-symbol j-help-voc-alist))) -(defun j-help-determine-symbol ( s point ) +(defun j-help--determine-symbol ( s point ) "Internal function to determine j symbols. Should not be called directly - string * int -> (string * string) list" (unless (or (< point 0) (< (length s) point)) - (j-some - (lambda (x) - (let* ((check-size (car x))) - (if (and - (<= (+ check-size point) (length s)) - (string-match (cadr x) (substring s point (+ point check-size)))) - (let* ((m (match-data)) - (ss (substring s (+ point (car m)) (+ point (cadr m))))) - (assoc ss (caddr x)))))) - j-help-dictionary-data-block))) + (let ((list j-help-dictionary-data-block) + val) + (while (and list (not val)) + (setq val (let* ((x (car list)) + (check-size (car x))) + (and + (<= (+ check-size point) (length s)) + (string-match (cadr x) (substring s point (+ point check-size))) + (let* ((m (match-data)) + (ss (substring s (+ point (car m)) (+ point (cadr m))))) + (assoc ss (caddr x))))) + list (cdr list))) + val))) (defun j-help-determine-symbol-at-point ( point ) "int -> (string * string) list" @@ -171,13 +161,12 @@ string * int -> (string * string) list" (let* ((bol (pos-bol)) (eol (pos-eol)) (s (buffer-substring-no-properties bol eol))) - (j-help-determine-symbol s (- point bol))))) + (j-help--determine-symbol s (- point bol))))) (defun j-help-branch-determine-symbol-at-point* ( string current-index target-index resolved-symbol ) - "" (if (> current-index target-index) resolved-symbol - (let ((next-symbol (j-help-determine-symbol string current-index))) + (let ((next-symbol (j-help--determine-symbol string current-index))) (j-help-branch-determine-symbol-at-point* string (+ current-index (length (or (car next-symbol) " "))) @@ -185,7 +174,6 @@ string * int -> (string * string) list" next-symbol)))) (defun j-help-branch-determine-symbol-at-point ( point ) - "" (save-excursion (goto-char point) (j-help-branch-determine-symbol-at-point* diff --git a/j-mode.el b/j-mode.el index 3f2743cb03..f6e7cd15fc 100644 --- a/j-mode.el +++ b/j-mode.el @@ -128,7 +128,7 @@ contents of current line." (save-excursion ;; skip empty/comment lines, if that leaves us in the first line, return 0 (while (and (= (forward-line -1) 0) - (if (looking-at "\\s *\\\\?$") + (if (looking-at "^[ \t]*\\(?:NB\\..*\\)?$") t (setq indent (save-match-data (back-to-indentation) @@ -168,9 +168,7 @@ contents of current line." kind of explicit definition we are `looking-at'. Modifies `match-data'!" ;; XXX we could dump the check for NB. if we prepending '^' to the others (cond ((j-thing-outside-string (rx (or (seq bow "define") - (seq ":" (* "\s") "0")) - (* "\s") - eol)) + (seq ":" (* "\s") "0")))) :multi-liner) ((j-thing-outside-string (rx (or (seq bow "def") " :")