emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/j-mode c6865b5 07/56: Initial commit for help documentatio


From: ELPA Syncer
Subject: [nongnu] elpa/j-mode c6865b5 07/56: Initial commit for help documentation look-up functionality.
Date: Sun, 29 Aug 2021 11:20:44 -0400 (EDT)

branch: elpa/j-mode
commit c6865b53b40b75cc929147a22368be94920fae5b
Author: Zachary Elliott <zach@nyu.edu>
Commit: Zachary Elliott <zach@nyu.edu>

    Initial commit for help documentation look-up functionality.
---
 j-help.el | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 192 insertions(+)

diff --git a/j-help.el b/j-help.el
new file mode 100644
index 0000000..98575eb
--- /dev/null
+++ b/j-help.el
@@ -0,0 +1,192 @@
+
+;;; j-help.el --- Help extension for j-mode.el
+
+;; Copyright (C) 2012 Zachary Elliott
+;;
+;; Authors: Zachary Elliott <ZacharyElliott1@gmail.com>
+;; URL: http://github.com/zellio/j-mode
+;; Version: 0.0.1
+;; Keywords: J, Languages
+
+;; This file is not part of GNU Emacs.
+
+;;; Commentary:
+
+;; Provides look up functions for the J software language documentation as
+;; provided by the VOC and other documentation on jsoftware.com
+
+;; This is not complete
+
+;;; License:
+
+;; This program is free software; you can redistribute it and/or modify it 
under
+;; the terms of the GNU General Public License as published by the Free 
Software
+;; Foundation; either version 3 of the License, or (at your option) any later
+;; version.
+;;
+;; This program is distributed in the hope that it will be useful, but WITHOUT
+;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS
+;; FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+;; details.
+;;
+;; You should have received a copy of the GNU General Public License along with
+;; GNU Emacs; see the file COPYING.  If not, write to the Free Software
+;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+;; USA.
+
+;;; Code:
+
+;;(set 'lexical-binding t)
+
+(defmacro -> ( &rest body )
+  "Alias for the funcall method"
+  `(funcall ,@body))
+
+(defmacro if-let ( binding then &optional else )
+  "Bind value according to BINDING and check for truthy-ness
+If the test passes then eval THEN with the BINDING varlist bound
+If no, eval ELSE with no binding"
+  (let* ((sym (caar binding))
+         (tst (cdar binding))
+         (gts (gensym)))
+    `(let ((,gts ,@tst))
+       (if ,gts
+         (let ((,sym ,gts))
+           ,then)
+         ,else))))
+
+(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 (eq (-> fn head) (-> 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) (< (-> fn x) (-> fn y))))))
+    (group-by* sl fn '() '() '())))
+
+(defgroup j-help nil
+  "Help documentation for j-mode"
+  :group 'applications
+  :prefix "j-help-")
+
+(defcustom j-help-local-dictionary-url ""
+  "Path to the local instance of the j-dictionary"
+  :type 'string
+  :group 'j-help)
+
+(defcustom j-help-remote-dictionary-url 
"http://www.jsoftware.com/help/dictionary";
+  "Path to the remote instance of the j-dictionary"
+  :type 'string
+  :group 'j-help)
+
+(defcustom j-help-symbol-search-branch-limit 5
+  "Distance from initial point they system can search for a valid symbol."
+  :type 'integer
+  :group 'j-help)
+
+(defconst j-help-voc-alist
+  '(("~" . "d220v") ("}" . "d530n") ("|" . "d230") ("#" . "d400")
+    ("{" . "d520") ("`" . "d610") ("_" . "d030") ("^" . "d200")
+    ("]" . "d500") ("\\" . "d430") (":" . "d432") ("." . "d431")
+    ("\"" . "d600n") ("[" . "d500") ("@" . "d620") ("?" . "d640")
+    ("=" . "d000") (";" . "d330") (":" . "d310n") ("/" . "d420")
+    ("." . "d300") ("-" . "d120") ("," . "d320") ("+" . "d100")
+    ("*" . "d110") ("<" . "d010") (">" . "d020") ("&" . "d630n")
+    ("%" . "d130") ("$" . "d210") ("~:" . "d222") ("~." . "d221")
+    ("}:" . "d532") ("}." . "d531") ("|:" . "d232") ("|." . "d231")
+    ("{:" . "d522") ("{." . "d521") ("x:" . "dxco") ("u:" . "duco")
+    ("t:" . "dtco") ("t." . "dtdotu") ("s:" . "dsco") ("r." . "drdot")
+    ("q:" . "dqco") ("p:" . "dpco") ("p." . "dpdot") ("o." . "dodot")
+    ("j." . "djdot") ("i:" . "dico") ("i." . "didot") ("f." . "dfdot")
+    ("e." . "dedot") ("d." . "dddot") ("b." . "dbdotn") ("a:" . "dadot")
+    ("a." . "dadot") ("`:" . "d612") ("_:" . "d032") ("_." . "d031")
+    ("^:" . "d202n") ("^." . "d201") ("\":" . "d602") ("\"." . "d601")
+    ("[:" . "d502") ("T." . "dtcapdot") ("@." . "d621") ("?." . "d641")
+    ("=:" . "d001") ("=." . "d001") (";:" . "d332") (";." . "d331")
+    ("::" . "d312") (":." . "d311") ("/:" . "d422") ("/." . "d421")
+    (".:" . "d301") (".." . "d301") ("-:" . "d122") ("-." . "d121")
+    (",:" . "d322") (",." . "d321") ("+:" . "d102") ("+." . "d101")
+    ("*:" . "d112") ("*." . "d111") ("<:" . "d012") ("<." . "d011")
+    (">:" . "d022") (">." . "d021") ("&:" . "d632") ("&." . "d631")
+    ("%:" . "d132") ("%." . "d131") ("$:" . "d212") ("$." . "d211")
+    ("#:" . "d402") ("#." . "d401") ("S:" . "dscapco") ("M." . "dmcapdot")
+    ("L:" . "dlcapco") ("L." . "dlcapdot") ("I." . "dicapdot") ("H." . 
"dhcapdot")
+    ("E." . "decapdot") ("D:" . "ddcapco") ("D." . "ddcapdot") ("C." . 
"dccapdot")
+    ("A." . "dacapdot") ("@:" . "d622") ("!:" . "d412") ("{::" . "d523")
+    ("p.." . "dpdotdot") ("_9:" . "dconsf") ("&.:" . "d631") ("NB." . "dnb"))
+  "(string * string) alist")
+
+(defconst j-help-dictionary-data-block
+  (mapcar
+   (lambda (l) (list (length (caar l))
+                     (regexp-opt (map 'list 'car l))
+                     l))
+   (delq nil (group-by j-help-voc-alist (lambda (x) (length (car x))))))
+  "(int * string * (string * string) alist) list")
+
+(defun j-help-valid-dictionary ()
+  "Return best defined dictionary"
+  (replace-regexp-in-string
+   "/$" ""
+   (cond ((not (string= "" j-help-local-dictionary-url))
+          j-help-local-dictionary-url)
+         ((not (string= "" j-help-remote-dictionary-url))
+          j-help-remote-dictionary-url))))
+
+(defun j-help-symbol-to-doc-url ( j-symbol )
+  "Convert J-SYMBOL into localtion URL"
+  (let ((alist-data (assoc j-symbol j-help-voc-alist))
+        (dic (j-help-valid-dictionary)))
+    (if (or (not alist-data) (string= dic ""))
+        (error "%s" "No dictionary found. Please specify a dictionary.")
+      (let ((name (car alist-data))
+            (doc-name (cdr alist-data)))
+      (format "%s/%s.%s" dic doc-name "htm")))))
+
+(defun j-help-determine-symbol ( s point )
+  "Internal function to determine j symbols. Should not be called directly"
+  (let* ((l (length s)))
+    (if (or (< point 0) (< l point)) '()
+      (some
+       (lambda (x)
+         (let* ((check-size (car x)))
+           (if (<= (+ check-size point) l)
+               (when (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))))
+
+(defun j-help-determine-symbol-at-point ( point )
+  (save-excursion
+    (goto-char point)
+    (let* ((bol (point-at-bol))
+           (eol (point-at-eol))
+           (s (buffer-substring-no-properties bol eol)))
+      (j-help-determine-symbol s (- point bol)))))
+
+;;(defun j-help-branch-determine-symbol-at-point ( point )
+;;  )
+
+;;;###autoload
+(defun j-help-lookup-symbol ( symbol )
+  "Lookup symbol in dictionary"
+  (interactive "sJ Symbol: ")
+  (let ((url (j-help-symbol-to-doc-url symbol)))
+    (message "Loading %s ..." url)
+    (browse-url url)))
+
+;;;###autoload
+(defun j-help-lookup-symbol-at-point ( point )
+  "Determine the symbol nearest to POINT and look it up in the dictionary"
+  (interactive "d")
+  (if-let ((symbol (j-help-determine-symbol-at-point point)))
+      (j-help-lookup-symbol symbol)
+    (error "No symbol could be determined for point %d" point)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]