diff --git a/doc/me.smd b/doc/me.smd index 1880253..653f387 100644 --- a/doc/me.smd +++ b/doc/me.smd @@ -2091,7 +2091,9 @@ [print-scheme(2)](print-scheme(2)) Create a new printer color and font scheme [print-setup(3)](print-setup(3)) Configure MicroEmacs's printer interface [py-doc(3)](py-doc(3)) Display Python module manual pages + [py-exec(3)](py-exec(3)) Executes the current Python script with or without command line arguments [py-format(3)](py-format(3)) Format Python source code using either black or yapf + [py-lint(3)](py-lint(3)) Check a Python script file for possible problems [query-replace-all-string(3)](query-replace-all-string(3)) Query replace string in a list of files [query-replace-string(2)](query-replace-string(2)) (esc C-r) Search and replace a string - with query [query-replace-string-in-files(3)](query-replace-string-in-files(3)) Conditionally search and replace strings @@ -2627,7 +2629,9 @@ [password-to-phonic(3)](password-to-phonic(3)) Convert a password to phonic string [print-setup(3)](print-setup(3)) Configure MicroEmacs's printer interface [py-doc(3)](py-doc(3)) Display Python module manual pages + [py-exec(3)](py-exec(3)) Executes the current Python script with or without command line arguments [py-format(3)](py-format(3)) Format Python source code using either black or yapf + [py-lint(3)](py-lint(3)) Check a Python script file for possible problems [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 @@ -3775,7 +3779,9 @@ [profile(9)](profile(9)) Shell user profile [py(9)](py(9)) Python Language File [py-doc(3)](py-doc(3)) Display Python module manual pages + [py-exec(3)](py-exec(3)) Executes the current Python script with or without command line arguments [py-format(3)](py-format(3)) Format Python source code using either black or yapf + [py-lint(3)](py-lint(3)) Check a Python script file for possible problems [python(9)](python(9)) Python Language File [query-replace-all-string(3)](query-replace-all-string(3)) Query replace string in a list of files [query-replace-string(2)](query-replace-string(2)) (esc C-r) Search and replace a string - with query @@ -43516,30 +43522,43 @@ $a [r(9)](r(9)) !! me-id: m3mac100 ! 3 py-doc +! 3 py-exec ! 3 py-format +! 3 py-lint +! 5 .py-lint.lint ## NAME |py-doc py-doc - display documentation for Python modules and packages +|py-exec + py-exec - executes the current Python script with or without command line arguments |py-format py-format - format Python source code using either black or yapf +|py-lint + py-lint - check a Python script file for possible problems +|.py-lint.lint + .py-lint.lint - linting command to be executed, default: yapf or back $a ## SYNOPSIS __py-doc__ ["package|function"] - __py-format__ + _n_ __py-exec__ + __py-format__ + __py-lint__ + set-variable _.py-lint.lint_ "_string_" + ## DESCRIPTION - __py-doc__ displays the manual page for a Python package module or package - within MicroEmacs.. + The __py-doc__ macro displays the manual page for a Python package module or + package within MicroEmacs. - You can fold or unfold the section and use the [item-list(3)](item-list(3)) - command to get an overview about section and classes in a module or - package. If no argment is given requests a package or function name from - the user via the command line. + You can fold or unfold the section and use the [item-list(3)](item-list(3)) command + to get an overview about section and classes in a module or package. + If no argument is given requests a package or function name from the + user is requested via the message line. The __py-format__ macro formats the currently edited file using one of the Python formatters either `yapf` or `black`. You can usually install these @@ -43547,19 +43566,56 @@ $a manager. To set your formatter to "black" even if you have "yapf" installed, you can change the value of the variable _.py-format.format_ to "black". - -## EXAMPLE + The __py-lint__ macro checks the currently edited file using the Python + package tool `pylint` which must be installed by the user for instance using + the standard package manager or using the Python package manager pip like + this: + + pip install pylint --user + + After executing the macro __py-lint__ a popup-window (`*pylint*`) displays the + warning messages of the `pylint` program, the user can click on the hilighted + lines showing warnings and jump directly to the problematic line. The same + can be achieved by pressing th ENTER key on the highlighted line using + the keyboard navigating to the warning or error line and pressing the ENTER key. + + Setting the variable _.py-lint.lint_ allows you to customize the linter + settings. + + The __py-exec__ macro executed the currently edited file using the python3 + command line interpreter. If any numeric argument is given before calling + the script, then the user is asked for command line arguments which should + be given on the message line. + + After executing the macro a popup-window (`*pyexec*`) displays the results + of the script execution. The user can click on the hilighted lines showing + warnings and jump directly to the problematic line in the source script. The + same can be achieved by pressing the ENTER key on the highlighted line using + the keyboard. + +## EXAMPLES ```{.emf} - py-doc "argparse" ; load the documentation of argparse module - py-doc "sys" - py-format ; formats the current Python file using yapf (or black) - set-variable .py-format.format "black" + py-doc "argparse" ; load the documentation of argparse module + py-doc "sys" + py-format ; formats the current Python file using yapf (or black) + set-variable .py-format.format "black" ``` + Here an example to lint the currently edited Python script. + +```{.emf} + ; by modifying the macro variable .py-lint.lint + ; you can add no standard options to pylint like here + set-variable .py-lint.lint "pylint --docstring-min-length 20 %s" + ; during editing an Python file press Esc x and then execute + py-lint +``` + ## NOTES - The __py-doc__ and the __py-format__ macros are defined in the file `pytools.emf`. + The __py-doc__, __py-exec__, __py-format__ and __py-lint__ macros are defined in the + file `pytools.emf`. ## SEE ALSO diff --git a/jasspa/macros/me.ehf b/jasspa/macros/me.ehf index 52a5d2c..b28d4a6 100644 --- a/jasspa/macros/me.ehf +++ b/jasspa/macros/me.ehf @@ -2174,7 +2174,9 @@ Miscellaneous Information lsprint-scheme(2)lmprint-scheme(2)le Create a new printer color and font scheme lsprint-setup(3)lmprint-setup(3)le Configure MicroEmacs's printer interface lspy-doc(3)lmpy-doc(3)le Display Python module manual pages + lspy-exec(3)lmpy-exec(3)le Executes the current Python script with or without command line arguments lspy-format(3)lmpy-format(3)le Format Python source code using either black or yapf + lspy-lint(3)lmpy-lint(3)le Check a Python script file for possible problems lsquery-replace-all-string(3)lmquery-replace-all-string(3)le Query replace string in a list of files lsquery-replace-string(2)lmquery-replace-string(2)le (esc C-r) Search and replace a string - with query lsquery-replace-string-in-files(3)lmquery-replace-string-in-files(3)le Conditionally search and replace strings @@ -2709,7 +2711,9 @@ Miscellaneous Information lspassword-to-phonic(3)lmpassword-to-phonic(3)le Convert a password to phonic string lsprint-setup(3)lmprint-setup(3)le Configure MicroEmacs's printer interface lspy-doc(3)lmpy-doc(3)le Display Python module manual pages + lspy-exec(3)lmpy-exec(3)le Executes the current Python script with or without command line arguments lspy-format(3)lmpy-format(3)le Format Python source code using either black or yapf + lspy-lint(3)lmpy-lint(3)le Check a Python script file for possible problems 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 @@ -3854,7 +3858,9 @@ Miscellaneous Information lsprofile(9)lmprofile(9)le Shell user profile lspy(9)lmpy(9)le Python Language File lspy-doc(3)lmpy-doc(3)le Display Python module manual pages + lspy-exec(3)lmpy-exec(3)le Executes the current Python script with or without command line arguments lspy-format(3)lmpy-format(3)le Format Python source code using either black or yapf + lspy-lint(3)lmpy-lint(3)le Check a Python script file for possible problems lspython(9)lmpython(9)le Python Language File lsquery-replace-all-string(3)lmquery-replace-all-string(3)le Query replace string in a list of files lsquery-replace-string(2)lmquery-replace-string(2)le (esc C-r) Search and replace a string - with query @@ -42936,30 +42942,43 @@ $a lsr(9)lmr(9)le ! 3 py-doc +! 3 py-exec ! 3 py-format +! 3 py-lint +! 5 .py-lint.lint cEcENAME cEcA |py-doc py-doc - display documentation for Python modules and packages +|py-exec + py-exec - executes the current Python script with or without command line arguments |py-format py-format - format Python source code using either black or yapf +|py-lint + py-lint - check a Python script file for possible problems +|.py-lint.lint + .py-lint.lint - linting command to be executed, default: yapf or back $a cESYNOPSIS cA cDpy-doccA ["package|function"] - cDpy-formatcA + cCncA cDpy-execcA + cDpy-formatcA + cDpy-lintcA + set-variable cC.py-lint.lintcA "cCstringcA" + cEDESCRIPTION cA - cDpy-doccA displays the manual page for a Python package module or package - within MicroEmacs.. + The cDpy-doccA macro displays the manual page for a Python package module or + package within MicroEmacs. - You can fold or unfold the section and use the lsitem-list(3)lmitem-list(3)le - command to get an overview about section and classes in a module or - package. If no argment is given requests a package or function name from - the user via the command line. + You can fold or unfold the section and use the lsitem-list(3)lmitem-list(3)le command + to get an overview about section and classes in a module or package. + If no argument is given requests a package or function name from the + user is requested via the message line. The cDpy-formatcA macro formats the currently edited file using one of the Python formatters either cGyapfcA or cGblackcA. You can usually install these @@ -42967,17 +42986,54 @@ $a manager. To set your formatter to "black" even if you have "yapf" installed, you can change the value of the variable cC.py-format.formatcA to "black". - -cEEXAMPLE cA + The cDpy-lintcA macro checks the currently edited file using the Python + package tool cGpylintcA which must be installed by the user for instance using + the standard package manager or using the Python package manager pip like + this: - py-doc "argparse" ; load the documentation of argparse module - py-doc "sys" - py-format ; formats the current Python file using yapf (or black) - set-variable .py-format.format "black" - + pip install pylint --user + + After executing the macro cDpy-lintcA a popup-window (cG*pylint*cA) displays the + warning messages of the cGpylintcA program, the user can click on the hilighted + lines showing warnings and jump directly to the problematic line. The same + can be achieved by pressing th ENTER key on the highlighted line using + the keyboard navigating to the warning or error line and pressing the ENTER key. + + Setting the variable cC.py-lint.lintcA allows you to customize the linter + settings. + + The cDpy-execcA macro executed the currently edited file using the python3 + command line interpreter. If any numeric argument is given before calling + the script, then the user is asked for command line arguments which should + be given on the message line. + + After executing the macro a popup-window (cG*pyexec*cA) displays the results + of the script execution. The user can click on the hilighted lines showing + warnings and jump directly to the problematic line in the source script. The + same can be achieved by pressing the ENTER key on the highlighted line using + the keyboard. + +cEEXAMPLES cA + +sB + py-doc "argparse" ; load the documentation of argparse module + py-doc "sys" + py-format ; formats the current Python file using yapf (or black) + set-variable .py-format.format "black" +sA + Here an example to lint the currently edited Python script. + +sB + ; by modifying the macro variable .py-lint.lint + ; you can add no standard options to pylint like here + set-variable .py-lint.lint "pylint --docstring-min-length 20 %s" + ; during editing an Python file press Esc x and then execute + py-lint +sA cENOTES cA - The cDpy-doccA and the cDpy-formatcA macros are defined in the file cGpytools.emfcA. + The cDpy-doccA, cDpy-execcA, cDpy-formatcA and cDpy-lintcA macros are defined in the + file cGpytools.emfcA. cESEE ALSO cA diff --git a/jasspa/macros/me.emf b/jasspa/macros/me.emf index 5ade81b..d49bd01 100644 --- a/jasspa/macros/me.emf +++ b/jasspa/macros/me.emf @@ -73,7 +73,7 @@ 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 rtools r-doc r-format r-lint r-exec -define-macro-file pytools py-doc py-format +define-macro-file pytools py-doc py-format py-lint py-exec define-macro-file zfile find-zfile zfile-setup define-macro-file gentags generate-tags-file define-macro-file dmf display-matching-fence diff --git a/jasspa/macros/pytools.emf b/jasspa/macros/pytools.emf index 7720b45..6756046 100644 --- a/jasspa/macros/pytools.emf +++ b/jasspa/macros/pytools.emf @@ -3,7 +3,7 @@ ; Created By : Detlef Groth, University of Potsdam ; Author : Detlef Groth, University of Potsdam ; Created : Wed Sep 25 15:42:35 2024 -; Last Modified : <241220.1806> +; Last Modified : <241221.1556> ; ; Description : Documentation viewer within MicroEmacs for ; Python @@ -98,3 +98,103 @@ define-macro py-format 0 reread-file !endif !emacro + +define-macro fhook-py-lint + buffer-init-hooks +!emacro + +define-macro py-lint + !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 + !force set-variable #l0 .lint + !if &seq #l0 "ERROR" + set-variable #l0 "pylint %s" + set-variable .lint #l0 + !endif + 2 pipe-shell-command &spr #l0 $buffer-fname "*pylint*" + !if &equ $result 1 + ml-write "Error: It seems that Python package pylint is not installed!" + !else + set-variable .buffer $buffer-bname + next-window-find-buffer "*pylint*" + buffer-init "py-lint" + set-variable :mouse-word-select py-lint-find-line + buffer-bind-create "bio" "return" "0" py-lint-find-line + !endif +!emacro + +0 define-macro py-lint-find-line + set-variable #l0 @wl + !if &xse #l0 "\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):.+" + next-window-find-buffer .py-lint.buffer + goto-line @s2 + beginning-of-line + @s3 forward-char + !else + ml-write "Not a error line!" + !endif +!emacro + +set-variable .fhook-py-lint.name "Python Lint" +set-variable .fhook-py-lint.setup ® "/history/fhook/py-lint" "acfhmw" +set-variable .fhook-py-lint.setup-mask "acfhmw" + +!if &and &sin "h" .fhook-py-lint.setup &band .hilight.flags 0x02 + !iif ¬ &exi .hilight.py-lint set-variable .hilight.py-lint &pinc .hilight.next 1 + 0 hilight .hilight.py-lint 2 200 $global-scheme + hilight .hilight.py-lint 0 "[/\\.A-Za-z0-9]+:[0-9]+:[0-9]+:" .scheme.link +!endif + +add-file-hook "*pylint*" fhook-py-lint + +; execute a Python file directly from MicroEmacs +define-macro fhook-py-exec + buffer-init-hooks +!emacro + +define-macro py-exec + !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 + ; command line arguments + set-variable #l1 "" + !if @? + set-variable #l1 @ml "Add command line arguments" + !endif + 2 pipe-shell-command &spr "python3 %s %s" $buffer-fname #l1 "*pyexec*" + set-variable .buffer $buffer-bname + next-window-find-buffer "*pyexec*" + buffer-init "py-exec" + set-variable :mouse-word-select py-exec-find-line + buffer-bind-create "bio" "return" "0" py-exec-find-line + +!emacro + +0 define-macro py-exec-find-line + set-variable #l0 @wl + !if &xse #l0 ".+line \\([0-9]+\\),.+" + next-window-find-buffer .py-exec.buffer + goto-line @s1 + !else + ml-write "Not a error line!" + !endif +!emacro + +set-variable .fhook-py-exec.name "Python Exec" +set-variable .fhook-py-exec.setup ® "/history/fhook/py-exec" "acfhmw" +set-variable .fhook-py-exec.setup-mask "acfhmw" + +!if &and &sin "h" .fhook-py-exec.setup &band .hilight.flags 0x02 + !iif ¬ &exi .hilight.py-exec set-variable .hilight.py-exec &pinc .hilight.next 1 + 0 hilight .hilight.py-exec 2 200 $global-scheme + hilight .hilight.py-exec 0 " File.*" .scheme.link +!endif + +add-file-hook "*pyexec*" fhook-py-exec