diff --git a/jasspa/macros/rdoc.emf b/jasspa/macros/rdoc.emf deleted file mode 100644 index 1d6bf30..0000000 --- a/jasspa/macros/rdoc.emf +++ /dev/null @@ -1,198 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; -; Author : $Author$ -; Created By : Detlef Groth -; Created : Thu Sep 26 19:12:38 2024 -; Last Modified : <241228.0952> -; -; Description -; -; Notes -; -; History -; -; Copyright (c) 2024 Detlef Groth. -; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -define-macro r-doc - !force set-variable #l0 @1 - !if ¬ $status - set-variable #l0 @ml00 "R help on" - !endif - !if &seq #l0 "" - !return - !endif - set-variable #l0 &rep #l0 "::" ":" - !if &xse #l0 "\\(.+\\):\\(.+\\)" - !if &or &seq @s1 "library" &seq @s1 "package" - set-variable #l1 &spr "options(useFancyQuotes = FALSE);library(help='%s')" @s2 - set-variable .package @s2 - !else - set-variable #l1 &spr "options(useFancyQuotes = FALSE);help('%s',package='%s',help_type='text')" @s2 @s1 - set-variable .package @s1 - !endif - !else - ; options(useFancyQuotes = FALSE); - set-variable .package "" - set-variable #l1 &spr "options(useFancyQuotes = FALSE);help('%s')" #l0 - !endif - 0 pipe-shell-command &spr "LANG=en_US Rscript -e \"%s\"" #l1 "*rdoc*" - set-variable :mouse-word-select r-doc-process-link - -1 buffer-mode "view" - beginning-of-buffer - ;set-variable $debug 2 - !force search-buffer "me" "During startup - Warning messages:" - !if $status - beginning-of-line - 1 kill-line - !endif - !force search-buffer "me" "Setting LC_.+ failed" - !while $status - beginning-of-line - 1 kill-line - !force search-buffer "me" "Setting LC_.+ failed" - !done - beginning-of-buffer - 3 kill-line - replace-string "_" "" - beginning-of-buffer - replace-string "^See Also:" "\ecESee Also:\ecA" - beginning-of-buffer - replace-string "^\\(\\u\\l[^ :]+:\\)$" "\ecE\\1\ecA" - beginning-of-buffer - replace-string " \\(package:[^ ]+\\) " " \els\\1\ele " - beginning-of-buffer - !force search-buffer "me" "^\\ecESee Also:" - !if $status - 2 forward-line - ;set-variable $debug 2 - beginning-of-line - set-variable #l1 0 - ; maximal 5 lines as &xse has problems with while - !while &less #l1 6 - ; &xse @wl "^\\S" does not work ... - -1 replace-string "'\\([^']+\\)'" "\els\\1\ele" - forward-line - beginning-of-line - set-variable #l1 &add #l1 1 - !done - !endif - beginning-of-buffer - ;; package documentation with Index: - !force search-buffer "me" "^\\ecEIndex:" - !if $status - 2 forward-line - beginning-of-line - set-variable #l1 0 - ; maximal 5 lines - !while &less #l1 100 - ; &xse @wl "^\\S" does not work ... - -1 replace-string "^\\([^\\s]+\\)" "\els\\1\ele" - !force forward-line - !if $status - beginning-of-line - !endif - set-variable #l1 &add #l1 1 - !done - beginning-of-buffer - !endif - ;execute-file "hkrdoc" - beginning-of-buffer - 1 buffer-mode "view" - !if &band $system 0x01 - ; some terminals might need this - screen-update - !endif - -!emacro -0 define-macro r-doc-test - 0 pipe-shell-command &spr "LANG=en_US Rscript -e \"%s\"" @1 "*tmp*" - find-buffer "*tmp*" - !force search-forward "No documentation for" - !if $status - set-variable .rdoc.docu &spr "No documentation for %s" @1 - delete-buffer "*tmp*" - !return - !endif - !force search-forward "there is no package called" - !if $status - set-variable .rdoc.docu &spr "Not such a package %s" @1 - delete-buffer "*tmp*" - !return - !endif - set-variable .rdoc.docu "OK" - delete-buffer "*tmp*" -!emacro -0 define-macro r-doc-process-link - ;set-variable $debug 3 - set-position "\x80" - set-variable #l0 $window-col - set-variable #l1 $window-line - ;set-variable $debug 2 - !force -2 search-forward "\ele" - !if $status - set-variable #l2 $window-col - set-variable #l3 $window-line - 3 backward-char - !force -2 search-backward "\els" - !if $status - set-variable #l4 $window-col - set-variable #l5 $window-line - 3 forward-char - ; all on same line? and - !if &and &equ #l1 #l3 &equ #l3 #l5 - !if &and &less #l0 #l2 &great #l0 #l4 - set-mark - search-forward "\ele" - 3 backward-char - copy-region - set-variable #l6 @y - -1 yank - ;3000 ml-write &spr "fetching %s" #l6 - !if &seq .rdoc.package "" - r-doc #l6 - !else - !if &equ &sin "package:" #l6 0 - r-doc &spr "%s::%s" .rdoc.package #l6 - !else - ; click on package:pkgname - r-doc #l6 - !endif - !endif - !endif - !endif - !endif - !endif -!emacro -; Advance to the next link in the forward direction -0 define-macro r-doc-forward-link - !if &les @# 0 - set-variable #l0 &sub 0 @# - #l0 r-doc-backward-link - !endif - !force @# search-forward "\els" - !if ¬ $status - ; Not found, force wrap, search and finish - beginning-of-buffer - search-forward "\els" - !endif -!emacro - -; Advance to the next link in the backward direction -0 define-macro r-doc-backward-link - !if &les @# 0 - set-variable #l0 &sub 0 @# - #l0 r-doc-forward-link - !endif - ; move back 3 chars so if we are currently on a link we do move - !force 3 backward-char - !force @# search-backward "\els" - !if ¬ $status - ; Not found, force wrap, search and finish - end-of-buffer - search-backward "\els" - !endif - ; move to the end of the \elm so the user can sensibly move forward - ; and so that subsequent forw/back-link moves work as expected. - 2 show-region -!emacro diff --git a/jasspa/macros/rtools.emf b/jasspa/macros/rtools.emf index 8828377..b265333 100644 --- a/jasspa/macros/rtools.emf +++ b/jasspa/macros/rtools.emf @@ -3,7 +3,7 @@ ; Author : Detlef Groth, University of Potsdam, Germany ; Created By : Detlef Groth ; Created : Wed Dec 4 17:39:58 2024 -; Last Modified : <241225.1039> +; Last Modified : <241228.1002> ; ; Description : functions useful to be used for R development ; @@ -167,4 +167,228 @@ define-macro r-exec ;!endif !emacro +define-macro fhook-rdoc + @# buffer-init "rdoc" + !if &seq $buffer-bname "*rdoc*" + ; Hyperlink with the key + buffer-bind-create "bio" "return" "0" r-doc-process-link + ; Move between links with the key + buffer-bind-create "bio" "tab" "" r-doc-forward-link + buffer-bind-create "bio" "S-tab" "" r-doc-backward-link + buffer-bind-create "bio" "space" "" scroll-down + !endif + buffer-init-hooks +!emacro + +; buffer-init variables +set-variable .fhook-rdoc.name "Rdoc" +set-variable .fhook-rdoc.setup ® "/history/fhook/rdoc" "acfhmw" +set-variable .fhook-rdoc.setup-mask "acfhmw" +;set-variable .fhook-rdoc.comment "|%||%|% | %||" + +!if &and &sin "h" .fhook-rdoc.setup &band .hilight.flags 0x02 + !iif ¬ &exi .hilight.rdoc set-variable .hilight.rdoc &pinc .hilight.next 1 + 0 hilight .hilight.rdoc 0 .scheme.text + !iif ¬ &exi ".hilight.r" !force execute-file "hkr" + hilight .hilight.rdoc 0xc0 "^cEUsage:cA" "Usage:" .hilight.r .scheme.header + hilight .hilight.rdoc 0xc0 "^cEExamples:cA" "Examples:" .hilight.r .scheme.header + hilight .hilight.r 0xc0 "cE(.+)cA" "\\1" .hilight.rdoc .scheme.header + hilight .hilight.r 0x44 "^cE" "" "cA" "" "" .scheme.header + hilight .hilight.rdoc 0x44 "^cE" "" "cA" "" "" .scheme.header + hilight .hilight.rdoc 0x44 "ls" "" "le" "" "" .scheme.link + ;hilight .hilight.rdoc 0x80 "^cEExamples:cB" .hilight.r .scheme.header +!endif + +!if &sin "f" .fhook-rdoc.setup + ; setup emf collapsing + set-variable .fhook-rdoc.collapse-open "^\ecE[A-Z]" + set-variable .fhook-rdoc.collapse-close "^\ecE[A-Z]\\|\\'\\)" + set-variable .fhook-rdoc.collapse-mnext "-1" +!endif +; setup item-list +set-variable .fhook-rdoc.item-list-s1 "^\ecE\\([A-Z].+\\)\ecA" +set-variable .fhook-rdoc.item-list-r1 "SECT \ecB\\1\ecA" +define-macro r-doc + !force set-variable #l0 @1 + !if ¬ $status + set-variable #l0 @ml00 "R help on" + !endif + !if &seq #l0 "" + !return + !endif + set-variable #l0 &rep #l0 "::" ":" + !if &xse #l0 "\\(.+\\):\\(.+\\)" + !if &or &seq @s1 "library" &seq @s1 "package" + set-variable #l1 &spr "options(useFancyQuotes = FALSE);library(help='%s')" @s2 + set-variable .package @s2 + !else + set-variable #l1 &spr "options(useFancyQuotes = FALSE);help('%s',package='%s',help_type='text')" @s2 @s1 + set-variable .package @s1 + !endif + !else + ; options(useFancyQuotes = FALSE); + set-variable .package "" + set-variable #l1 &spr "options(useFancyQuotes = FALSE);help('%s')" #l0 + !endif + 0 pipe-shell-command &spr "LANG=en_US Rscript -e \"%s\"" #l1 "*rdoc*" + set-variable :mouse-word-select r-doc-process-link + buffer-bind-create "bio" "return" "0" r-doc-process-link + -1 buffer-mode "view" + beginning-of-buffer + ;set-variable $debug 2 + !force search-buffer "me" "During startup - Warning messages:" + !if $status + beginning-of-line + 1 kill-line + !endif + !force search-buffer "me" "Setting LC_.+ failed" + !while $status + beginning-of-line + 1 kill-line + !force search-buffer "me" "Setting LC_.+ failed" + !done + beginning-of-buffer + 3 kill-line + replace-string "_" "" + beginning-of-buffer + replace-string "^See Also:" "\ecESee Also:\ecA" + beginning-of-buffer + replace-string "^\\(\\u\\l[^ :]+:\\)$" "\ecE\\1\ecA" + beginning-of-buffer + replace-string " \\(package:[^ ]+\\) " " \els\\1\ele " + beginning-of-buffer + !force search-buffer "me" "^\\ecESee Also:" + !if $status + 2 forward-line + ;set-variable $debug 2 + beginning-of-line + set-variable #l1 0 + ; maximal 5 lines as &xse has problems with while + !while &less #l1 6 + ; &xse @wl "^\\S" does not work ... + -1 replace-string "'\\([^']+\\)'" "\els\\1\ele" + forward-line + beginning-of-line + set-variable #l1 &add #l1 1 + !done + !endif + beginning-of-buffer + ;; package documentation with Index: + !force search-buffer "me" "^\\ecEIndex:" + !if $status + 2 forward-line + beginning-of-line + set-variable #l1 0 + ; maximal 5 lines + !while &less #l1 100 + ; &xse @wl "^\\S" does not work ... + -1 replace-string "^\\([^\\s]+\\)" "\els\\1\ele" + !force forward-line + !if $status + beginning-of-line + !endif + set-variable #l1 &add #l1 1 + !done + beginning-of-buffer + !endif + ;execute-file "hkrdoc" + beginning-of-buffer + 1 buffer-mode "view" + !if &band $system 0x01 + ; some terminals might need this + screen-update + !endif + +!emacro +0 define-macro r-doc-test + 0 pipe-shell-command &spr "LANG=en_US Rscript -e \"%s\"" @1 "*tmp*" + find-buffer "*tmp*" + !force search-forward "No documentation for" + !if $status + set-variable .rdoc.docu &spr "No documentation for %s" @1 + delete-buffer "*tmp*" + !return + !endif + !force search-forward "there is no package called" + !if $status + set-variable .rdoc.docu &spr "Not such a package %s" @1 + delete-buffer "*tmp*" + !return + !endif + set-variable .rdoc.docu "OK" + delete-buffer "*tmp*" +!emacro +0 define-macro r-doc-process-link + ;set-variable $debug 3 + set-position "\x80" + set-variable #l0 $window-col + set-variable #l1 $window-line + ;set-variable $debug 2 + !force -2 search-forward "\ele" + !if $status + set-variable #l2 $window-col + set-variable #l3 $window-line + 3 backward-char + !force -2 search-backward "\els" + !if $status + set-variable #l4 $window-col + set-variable #l5 $window-line + 3 forward-char + ; all on same line? and + !if &and &equ #l1 #l3 &equ #l3 #l5 + !if &and &less #l0 #l2 &great #l0 #l4 + set-mark + search-forward "\ele" + 3 backward-char + copy-region + set-variable #l6 @y + -1 yank + ;3000 ml-write &spr "fetching %s" #l6 + !if &seq .r-doc.package "" + r-doc #l6 + !else + !if &equ &sin "package:" #l6 0 + r-doc &spr "%s::%s" .r-doc.package #l6 + !else + ; click on package:pkgname + r-doc #l6 + !endif + !endif + !endif + !endif + !endif + !endif +!emacro +; Advance to the next link in the forward direction +0 define-macro r-doc-forward-link + !if &les @# 0 + set-variable #l0 &sub 0 @# + #l0 r-doc-backward-link + !endif + !force @# search-forward "\els" + !if ¬ $status + ; Not found, force wrap, search and finish + beginning-of-buffer + search-forward "\els" + !endif +!emacro + +; Advance to the next link in the backward direction +0 define-macro r-doc-backward-link + !if &les @# 0 + set-variable #l0 &sub 0 @# + #l0 r-doc-forward-link + !endif + ; move back 3 chars so if we are currently on a link we do move + !force 3 backward-char + !force @# search-backward "\els" + !if ¬ $status + ; Not found, force wrap, search and finish + end-of-buffer + search-backward "\els" + !endif + ; move to the end of the \elm so the user can sensibly move forward + ; and so that subsequent forw/back-link moves work as expected. + 2 show-region +!emacro