Ivan Andrus avatar Ivan Andrus committed 876a6e5

Fixed inline help to be faster and more robust
Introduced emacs.gaprc

Comments (0)

Files changed (2)

+# -*- gap -*-
+
+# Override the screen help mechanism to be more robust and faster.
+if IsBound(HELP_VIEWER_INFO) and IsRecord(HELP_VIEWER_INFO) then
+
+    HELP_VIEWER_INFO.orig_screen := HELP_VIEWER_INFO.screen;
+    HELP_VIEWER_INFO.screen := rec( type := "text",
+                                    show := function(lines)
+        local tmpDir, filename;
+
+        # Standardize input
+        if not IsRecord( lines ) then
+            lines := rec(lines := lines,
+                         exitAtEnd := true,
+                         start := 0 );
+        fi;
+
+        # Dump all the data to a temp file.  This should be much
+        # faster than paging it all, and we don't have to worry about
+        # incorrectly parsing the paging construct if it ever changes.
+        tmpDir := DirectoryTemporary( );
+        filename := Filename( tmpDir, "emacs.help" );
+        FileString( filename, lines.lines );
+
+        # This is what emacs will parse to know where to look for help data
+        Print( "GAP Help in ", filename, " with offset ", lines.start );
+    end );
+
+fi;
 (defvar gap-pending-input nil
   "Holds input to feed slowly to GAP when starting with buffer as input.")
 
+(defvar gap-mode-gaprc
+  (let ((gaprc (concat (file-name-directory
+                        (or load-file-name
+                            (buffer-file-name)))
+                       "emacs.gaprc")))
+    (and (file-exists-p gaprc)
+         gaprc))
+  "The path to the emacs-specific gaprc file.
+This file will be loaded after GAP has successfully started up.")
+
 (defvar gap-pending-pointer nil)
 
 (defvar gap-completing-buffer nil
 buffer to the GAP session as initial standard input."
   (interactive "P")
   (if (not (gap-running-p))
-      (let (proc)
-        (setq gap-pending-input (if send-buffer (buffer-string) nil))
+      (let ((have-input (or gap-mode-gaprc send-buffer))
+            proc)
+        (setq gap-pending-input
+              (if have-input
+                  (concat (if gap-mode-gaprc
+                              (format "Read(\"%s\");\n"
+                                      gap-mode-gaprc)
+                            nil)
+                          (if send-buffer (buffer-string) nil))))
         (setq gap-pending-pointer 0)
         (setq gap-process-buffer
               (get-start-process gap-executable "GAP"
                                  gap-start-options))
         (setq proc (get-buffer-process gap-process-buffer))
         (gap-process-mode)
-        (if (not send-buffer)
-            (set-process-filter proc 'gap-output-filter)
-          (set-process-filter proc 'gap-startfile-filter)))
+        (if have-input
+            (set-process-filter proc 'gap-startfile-filter)
+          (set-process-filter proc 'gap-output-filter)))
     (if send-buffer
         (let (proc)
           (setq gap-pending-input (buffer-string))
 It must handle the continuation prompts by stripping them and
 sending spaces to continue the output until finished."
   (let ((cbuf (current-buffer)))
-    (set-buffer "*Help*")
+    (set-buffer (get-buffer-create "*Help*"))
     (setq buffer-read-only nil)                                     ;; GEZ: so we can put help info into the buffer
     (set (make-local-variable 'show-trailing-whitespace) nil)
     (goto-char (point-max))
       (gap-cleanup-help-buffer)
       (goto-char (point-min))
       (set-process-filter proc 'gap-output-filter))
+    (when (re-search-forward (concat "^GAP Help in \\(.*\\) with offset \\([0-9]+\\)$") nil t)                ;;GEZ: make sure get the end of it all
+      (let ((help-file (match-string 1))
+            (offset (string-to-number (match-string 2))))
+        (insert-file-contents help-file nil nil nil t)
+        (gap-cleanup-help-buffer)
+        (set-buffer-modified-p nil)
+
+        ;; Fancy tricks to make changes to point "stick"
+        (pop-to-buffer (current-buffer))
+        (goto-char (point-min))
+        (forward-line (1- offset))
+        (recenter-top-bottom 2)
+        (pop-to-buffer cbuf)
+
+        (set-process-filter proc 'gap-output-filter)))
     (set-buffer cbuf)))
 
 (defun gap-cleanup-help-buffer ()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.