diff --git a/doc/me.smd b/doc/me.smd index 67c80a9..4a5fc85 100644 --- a/doc/me.smd +++ b/doc/me.smd @@ -1072,7 +1072,7 @@ [list-buffers(2)](list-buffers(2)) (C-x C-b) List all buffers and show their status [osd-help(3)](osd-help(3)) GUI based on-line help [pydoc(3)](pydoc(3)) Display Python module manual pages - [rdoc(3)](rdoc(3)) Display R function and package manual pages + [r-doc(3)](r-doc(3)) Display R function and package manual pages !! me-id: amicr021 ! Operating Modes @@ -2099,7 +2099,9 @@ [quote-char(2)](quote-char(2)) (C-q) Insert literal character [rcs-file(2)](rcs-file(2)) (C-x C-q) Handle Revision Control System (RCS) files [rdiff(3)](rdiff(3)) Recursively compare files or directories - [rdoc(3)](rdoc(3)) Display R function and package manual pages + [r-doc(3)](r-doc(3)) Display R function and package manual pages + [r-format(3)](r-format(3)) Format the currently edited R script file + [r-lint(3)](r-lint(3)) Source code check of the currently edited R script file [read-file(2)](read-file(2)) (C-x C-r) Find and load file replacing current buffer [read-registry(2)](read-registry(2)) Read in a registry definition file [read-session(3)](read-session(3)) Read in session information @@ -2626,7 +2628,9 @@ [query-replace-all-string(3)](query-replace-all-string(3)) Query replace string in a list of files [query-replace-string-in-files(3)](query-replace-string-in-files(3)) Conditionally search and replace strings across files [rdiff(3)](rdiff(3)) Recursively compare files or directories - [rdoc(3)](rdoc(3)) Display R function and package manual pages + [r-doc(3)](r-doc(3)) Display R function and package manual pages + [r-format(3)](r-format(3)) Format the currently edited R script file + [r-lint(3)](r-lint(3)) Source code check of the currently edited R script file [read-session(3)](read-session(3)) Read in session information [replace-all-pairs(3)](replace-all-pairs(3)) Replace string pairs in a list of files [replace-all-string(3)](replace-all-string(3)) Replace string with new string in a list of files @@ -3781,7 +3785,9 @@ [rc(9)](rc(9)) Microsoft Developer resource file [rcs-file(2)](rcs-file(2)) (C-x C-q) Handle Revision Control System (RCS) files [rdiff(3)](rdiff(3)) Recursively compare files or directories - [rdoc(3)](rdoc(3)) Display R function and package manual pages + [r-doc(3)](r-doc(3)) Display R function and package manual pages + [r-format(3)](r-format(3)) Format the currently edited R script file + [r-lint(3)](r-lint(3)) Source code check of the currently edited R script file [read-file(2)](read-file(2)) (C-x C-r) Find and load file replacing current buffer [read-registry(2)](read-registry(2)) Read in a registry definition file [read-session(3)](read-session(3)) Read in session information @@ -4992,6 +4998,7 @@ ## Development History + - [241120] - fixing Find osd type for wrong key shortcut - improved abbreviation handling for R and Python Esc Esc now expands @@ -43424,22 +43431,30 @@ $a [scheme-editor(3)](scheme-editor(3)) !! me-id: m3mac099 -! 3 rdoc +! 3 r-doc +! 3 r-format +! 3 r-lint ## NAME - -|rdoc - rdoc - display documentation for R functions and packages +|r-doc + r-doc - display documentation for R functions and packages +|r-format + r-format - format a R script using the formatR library +|r-lint + r-lint - R source code linter using the lintr library $a ## SYNOPSIS - __rdoc__ ["package::function|function"] + __r-doc__ ["package::function|function"] + __r-format__ + __r-lint__ + ## DESCRIPTION - Displays in a hypertext browser with R syntax hilighting the manual pages - for R packages or R functions. + The __r-doc__ macro displays in a hypertext browser with R syntax hilighting + the manual pages for R packages or R functions. You can fold or unfold the section and use the [item-list(3)](item-list(3)) command to navigate the documentation sections. If no argment is given @@ -43449,19 +43464,36 @@ $a using the syntax "pkgname::funcname". Links to other functions and to the main package overview are shown with hilights in the normal text. Usage and Examples sections use R highlighting. - + + The __r-format__ macro formats the currently edited R script file using the + formats the currently edited file using the R library `formatR` which must + be installed by the user for instance using the usual + `install.packages('formatR')` syntax from within a R console. + + The __r-lint__ macro checks the currently edited file using the R package + `lintr` which must be installed by the user for instance using the usual + `install.packages('lintr)` syntax from within a R console. + + After executing the macro a popup-window (`*lintr*`) displays the warning + messages of the linter package, the user can click on the hilighted lines + showing warnings and jump directly to the problematic line. The same can + be achieved by pressing the ENTER key on the hilighted line. + ## EXAMPLE ```{.emf} - rdoc ; requests a help page from the user - rdoc "plot" ; function documentation - rdoc "cluster::pam" ; function pam in package cluster - rdoc "package::cluster" ; package overview with functions + r-doc ; requests a help page from the user + r-doc "plot" ; plot function documentation + r-doc "cluster::pam" ; function pam in package cluster docu + r-doc "package::cluster" ; package overview with functions + r-format ; formats and reloads the currently edited R script + r-lint ; gives code advise for the currently edited R script ``` ## NOTES - __rdoc__ macro is defined in file `hkrdoc.emf`. + __r-doc__ macro is defined in file `hkrdoc.emf`. The macros __r-format__ + and __r-lint__ are implemented in the file `rtools.emf`. ## SEE ALSO diff --git a/jasspa/macros/hkr.emf b/jasspa/macros/hkr.emf index f383676..7e7e414 100644 --- a/jasspa/macros/hkr.emf +++ b/jasspa/macros/hkr.emf @@ -15,7 +15,7 @@ define-macro fhook-r @# buffer-init "r" buffer-init-hooks !emacro - +define-macro-file rtools r-lint r-format ; buffer-init variables set-variable .fhook-r.name "R/S-Plus" set-variable .fhook-r.setup ® "/history/fhook/r" "bdfghopx" diff --git a/jasspa/macros/hkrdoc.emf b/jasspa/macros/hkrdoc.emf index 2eec460..8fa87c1 100644 --- a/jasspa/macros/hkrdoc.emf +++ b/jasspa/macros/hkrdoc.emf @@ -3,7 +3,7 @@ ; Author : $Author$ ; Created By : Detlef Groth ; Created : Thu Sep 26 14:43:10 2024 -; Last Modified : <240926.1936> +; Last Modified : <241212.1427> ; ; Description ; @@ -56,5 +56,3 @@ set-variable .fhook-rdoc.setup-mask "acfhmw" set-variable .fhook-rdoc.item-list-s1 "^\ecE\\([A-Z].+\\)\ecA" set-variable .fhook-rdoc.item-list-r1 "SECT \ecB\\1\ecA" - -1000 ml-write "load new hkrdoc" diff --git a/jasspa/macros/me.ehf b/jasspa/macros/me.ehf index eb8d98b..a4ce9d8 100644 --- a/jasspa/macros/me.ehf +++ b/jasspa/macros/me.ehf @@ -1166,7 +1166,7 @@ Miscellaneous Information lslist-buffers(2)lmlist-buffers(2)le (C-x C-b) List all buffers and show their status lsosd-help(3)lmosd-help(3)le GUI based on-line help lspydoc(3)lmpydoc(3)le Display Python module manual pages - lsrdoc(3)lmrdoc(3)le Display R function and package manual pages + lsr-doc(3)lmr-doc(3)le Display R function and package manual pages ! Operating Modes cEcEOPERATING MODES cEcA @@ -2182,7 +2182,9 @@ Miscellaneous Information lsquote-char(2)lmquote-char(2)le (C-q) Insert literal character lsrcs-file(2)lmrcs-file(2)le (C-x C-q) Handle Revision Control System (RCS) files lsrdiff(3)lmrdiff(3)le Recursively compare files or directories - lsrdoc(3)lmrdoc(3)le Display R function and package manual pages + lsr-doc(3)lmr-doc(3)le Display R function and package manual pages + lsr-format(3)lmr-format(3)le Format the currently edited R script file + lsr-lint(3)lmr-lint(3)le Source code check of the currently edited R script file lsread-file(2)lmread-file(2)le (C-x C-r) Find and load file replacing current buffer lsread-registry(2)lmread-registry(2)le Read in a registry definition file lsread-session(3)lmread-session(3)le Read in session information @@ -2708,7 +2710,9 @@ Miscellaneous Information lsquery-replace-all-string(3)lmquery-replace-all-string(3)le Query replace string in a list of files lsquery-replace-string-in-files(3)lmquery-replace-string-in-files(3)le Conditionally search and replace strings across files lsrdiff(3)lmrdiff(3)le Recursively compare files or directories - lsrdoc(3)lmrdoc(3)le Display R function and package manual pages + lsr-doc(3)lmr-doc(3)le Display R function and package manual pages + lsr-format(3)lmr-format(3)le Format the currently edited R script file + lsr-lint(3)lmr-lint(3)le Source code check of the currently edited R script file lsread-session(3)lmread-session(3)le Read in session information lsreplace-all-pairs(3)lmreplace-all-pairs(3)le Replace string pairs in a list of files lsreplace-all-string(3)lmreplace-all-string(3)le Replace string with new string in a list of files @@ -3860,7 +3864,9 @@ Miscellaneous Information lsrc(9)lmrc(9)le Microsoft Developer resource file lsrcs-file(2)lmrcs-file(2)le (C-x C-q) Handle Revision Control System (RCS) files lsrdiff(3)lmrdiff(3)le Recursively compare files or directories - lsrdoc(3)lmrdoc(3)le Display R function and package manual pages + lsr-doc(3)lmr-doc(3)le Display R function and package manual pages + lsr-format(3)lmr-format(3)le Format the currently edited R script file + lsr-lint(3)lmr-lint(3)le Source code check of the currently edited R script file lsread-file(2)lmread-file(2)le (C-x C-r) Find and load file replacing current buffer lsread-registry(2)lmread-registry(2)le Read in a registry definition file lsread-session(3)lmread-session(3)le Read in session information @@ -5067,6 +5073,7 @@ Miscellaneous Information cEDevelopment History cA + - [241120] - fixing Find osd type for wrong key shortcut - improved abbreviation handling for R and Python Esc Esc now expands @@ -42846,22 +42853,30 @@ $a cESEE ALSO cA lsscheme-editor(3)lmscheme-editor(3)le -! 3 rdoc +! 3 r-doc +! 3 r-format +! 3 r-lint cEcENAME cEcA - -|rdoc - rdoc - display documentation for R functions and packages +|r-doc + r-doc - display documentation for R functions and packages +|r-format + r-format - format a R script using the formatR library +|r-lint + r-lint - R source code linter using the lintr library $a cESYNOPSIS cA - cDrdoccA ["package::function|function"] + cDr-doccA ["package::function|function"] + cDr-formatcA + cDr-lintcA + cEDESCRIPTION cA - Displays in a hypertext browser with R syntax hilighting the manual pages - for R packages or R functions. + The cDr-doccA macro displays in a hypertext browser with R syntax hilighting + the manual pages for R packages or R functions. You can fold or unfold the section and use the lsitem-list(3)lmitem-list(3)le command to navigate the documentation sections. If no argment is given @@ -42871,18 +42886,35 @@ $a using the syntax "pkgname::funcname". Links to other functions and to the main package overview are shown with hilights in the normal text. Usage and Examples sections use R highlighting. - + + The cDr-formatcA macro formats the currently edited R script file using the + formats the currently edited file using the R library cGformatRcA which must + be installed by the user for instance using the usual + cGinstall.packages('formatR')cA syntax from within a R console. + + The cDr-lintcA macro checks the currently edited file using the R package + cGlintrcA which must be installed by the user for instance using the usual + cGinstall.packages('lintr)cA syntax from within a R console. + + After executing the macro a popup-window (cG*lintr*cA) displays the warning + messages of the linter package, the user can click on the hilighted lines + showing warnings and jump directly to the problematic line. The same can + be achieved by pressing the ENTER key on the hilighted line. + cEEXAMPLE cA sB - rdoc ; requests a help page from the user - rdoc "plot" ; function documentation - rdoc "cluster::pam" ; function pam in package cluster - rdoc "package::cluster" ; package overview with functions + r-doc ; requests a help page from the user + r-doc "plot" ; plot function documentation + r-doc "cluster::pam" ; function pam in package cluster docu + r-doc "package::cluster" ; package overview with functions + r-format ; formats and reloads the currently edited R script + r-lint ; gives code advise for the currently edited R script sA cENOTES cA - cDrdoccA macro is defined in file cGhkrdoc.emfcA. + cDr-doccA macro is defined in file cGhkrdoc.emfcA. The macros cDr-formatcA + and cDr-lintcA are implemented in the file cGrtools.emfcA. cESEE ALSO cA diff --git a/jasspa/macros/me.emf b/jasspa/macros/me.emf index dbd69be..a53afd4 100644 --- a/jasspa/macros/me.emf +++ b/jasspa/macros/me.emf @@ -72,7 +72,7 @@ define-macro-file mail mail mail-check stop-mail-check define-macro-file fileopen osd-file-open osd-get-file define-macro-file spellaut auto-spell auto-spell-menu define-macro-file hkinfo info info-on info-goto-link -define-macro-file rdoc rdoc +define-macro-file rdoc r-doc define-macro-file hkpydoc pydoc define-macro-file zfile find-zfile zfile-setup define-macro-file gentags generate-tags-file diff --git a/jasspa/macros/rdoc.emf b/jasspa/macros/rdoc.emf index ae51542..151047e 100644 --- a/jasspa/macros/rdoc.emf +++ b/jasspa/macros/rdoc.emf @@ -3,7 +3,7 @@ ; Author : $Author$ ; Created By : Detlef Groth ; Created : Thu Sep 26 19:12:38 2024 -; Last Modified : <240928.0506> +; Last Modified : <241212.1436> ; ; Description ; @@ -14,7 +14,7 @@ ; Copyright (c) 2024 Detlef Groth. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -define-macro rdoc +define-macro r-doc !force set-variable #l0 @1 !if ¬ $status set-variable #l0 @ml00 "R help on" @@ -36,8 +36,6 @@ define-macro rdoc set-variable .package "" set-variable #l1 &spr "options(useFancyQuotes = FALSE);help('%s')" #l0 !endif - r-doc-test #l1 - 1000 ml-write .docu 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" @@ -152,13 +150,13 @@ define-macro r-doc-test -1 yank ;3000 ml-write &spr "fetching %s" #l6 !if &seq .rdoc.package "" - rdoc #l6 + r-doc #l6 !else !if &equ &sin "package:" #l6 0 - rdoc &spr "%s::%s" .rdoc.package #l6 + r-doc &spr "%s::%s" .rdoc.package #l6 !else ; click on package:pkgname - rdoc #l6 + r-doc #l6 !endif !endif !endif diff --git a/jasspa/macros/rtools.emf b/jasspa/macros/rtools.emf new file mode 100644 index 0000000..49acfd1 --- /dev/null +++ b/jasspa/macros/rtools.emf @@ -0,0 +1,116 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; Author : Detlef Groth, University of Potsdam, Germany +; Created By : Detlef Groth +; Created : Wed Dec 4 17:39:58 2024 +; Last Modified : <241212.1528> +; +; Description : functions useful to be used for R development +; +; Notes : - r-format requires the R package formatR to be installed +; - r-lint requires the R package lintr to be installed +; +; History : 2024-12-04 - first version +; +; Copyright (c) 2024 Detlef Groth, University of Potsdam, Germany +; License : Same as MicroEmacs - GPL 2 +; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +define-macro r-format + !if &bmod "edit" + set-variable #l0 @mc5 "Save buffer first (?/y/n) ? " "nNyY" "(Y)es, (N)o, (C-g)Abort ? " + !if &iseq #l0 "y" + save-buffer + !endif + !endif + set-variable #l0 ® &spr "/history/%s/char-set" %platform "" + set-variable #l0 &xre #l0 "iso" "ISO-" #l0 + set-variable #l0 &xre #l0 "cp" "CP" #l0 + set-variable #l0 &xre #l0 "microsoft-" "" #l0 + 2 pipe-shell-command &spr "Rscript -e 'options(\"encoding\"=\"%s\");formatR::tidy_file(\"%s\")'" #l0 $buffer-fname "*command*" + !if &equ $result 1 + ml-write "Error: It seems that R package formatR is not installed!" + !else + 0 reread-file + !endif +!emacro + +0 define-macro r-rscript + !force set-variable #l0 %rscript-com + ;set-variable $file-names "/home/dgroth/.local/share/fonts/*" + !if &seq #l0 "ERROR" + set-variable %rscript-com "Rscript" + !endif + ; TODO: + ; - Windows check for set-variable $file-names "c:/Program File/R/*" + ; - then check for bin/x64/Rscript.exe file + !if &seq &which %rscript-com "" + 1000 ml-write &spr "Error: Executable '%s' is not in the path! Please install it!" %rscript-com + !abort + !else + ml-write "all fine" + !endif + +!emacro + +define-macro r-lint + !force set-variable #l1 .lint + set-variable #l0 ® &spr "/history/%s/char-set" %platform "" + set-variable #l0 &xre #l0 "iso" "ISO-" #l0 + set-variable #l0 &xre #l0 "cp" "CP" #l0 + set-variable #l0 &xre #l0 "microsoft-" "" #l0 + ;!if &seq #l1 "ERROR" + set-variable .lint "Rscript -e 'options(\"encoding\"=\"%s\");library(lintr);lintr::lint(\"%s\",linters = linters_with_defaults( indentation_linter = indentation_linter(indent = 4L) ))'" #l0 + set-variable #l1 .lint + ;!endif + !if &bmod "edit" + set-variable #l2 @mc5 "Save buffer first (?/y/n) ? " "nNyY" "(Y)es, (N)o, (C-g)Abort ? " + !if &iseq #l2 "y" + save-buffer + !endif + !endif + 2 pipe-shell-command &spr #l1 #l0 $buffer-fname "*lintr*" + !if &equ $result 1 + ml-write "Error: It seems that R package lintr is not installed!" + !else + set-variable .buffer $buffer-bname + next-window-find-buffer "*lintr*" + buffer-init "r-lint" + set-variable :mouse-word-select r-lint-find-line + buffer-bind-create "bio" "return" "0" r-lint-find-line + !endif +!emacro + +0 define-macro r-lint-find-line + set-variable #l0 @wl + !if &xse #l0 "\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):.+" + next-window-find-buffer .r-lint.buffer + goto-line @s2 + beginning-of-line + @s3 forward-char + !else + ml-write "Not a error line!" + !endif +!emacro + +define-macro fhook-r-lint + buffer-init-hooks +!emacro + +set-variable .fhook-r-lint.name "R Lint" +set-variable .fhook-r-lint.setup ® "/history/fhook/r-lint" "acfhmw" +set-variable .fhook-r-lint.setup-mask "acfhmw" + +!if &and &sin "h" .fhook-r-lint.setup &band .hilight.flags 0x02 + !iif ¬ &exi .hilight.r-lint set-variable .hilight.r-lint &pinc .hilight.next 1 + 0 hilight .hilight.r-lint 2 200 $global-scheme + hilight .hilight.r-lint 0 "[/\\.A-Za-z0-9]+:[0-9]+:[0-9]+:" .scheme.link + hilight .hilight.r-lint 1 "commas_linter" .scheme.operator + hilight .hilight.r-lint 1 "infix_spaces_linter" .scheme.operator + hilight .hilight.r-lint 1 "function_left_parentheses_linter" .scheme.operator + hilight .hilight.r-lint 1 "indentation_linter" .scheme.operator + ;hilight .hilight.r-lint 0 "\[.+\]" .scheme.operator ; does not work +!endif + +add-file-hook "*lintr*" fhook-r-lint +