Skip to content

Commit

Permalink
completig renaming to py-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Detlef Groth committed Dec 20, 2024
1 parent 8863078 commit bff0f2b
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 37 deletions.
31 changes: 25 additions & 6 deletions doc/me.smd
Original file line number Diff line number Diff line change
Expand Up @@ -2091,6 +2091,7 @@
[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-format(3)](py-format(3)) Format Python source code using either black or yapf
[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
Expand Down Expand Up @@ -2626,6 +2627,7 @@
[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-format(3)](py-format(3)) Format Python source code using either black or yapf
[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
Expand Down Expand Up @@ -3773,6 +3775,7 @@
[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-format(3)](py-format(3)) Format Python source code using either black or yapf
[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
Expand Down Expand Up @@ -43513,34 +43516,50 @@ $a
[r(9)](r(9))
!! me-id: m3mac100
! 3 py-doc
! 3 py-format
## NAME


|pydoc
|py-doc
py-doc - display documentation for Python modules and packages
|py-format
py-format - format Python source code using either black or yapf
$a

## SYNOPSIS

__py-doc__ ["package|function"]
__py-doc__ ["package|function"]
__py-format__

## DESCRIPTION

Displays with the manual page for a Python package module or package.
__py-doc__ 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.

The __py-format__ macro formats the currently edited file using one of the
Python formatters either `yapf` or `black`. You can usually install these
application using your systems package manager or using the pip package
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

py-doc "argparse"
```{.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"
```

## NOTES

__py-doc__ macro is defined in file `pytools.emf`.
The __py-doc__ and the __py-format__ macros are defined in the file `pytools.emf`.

## SEE ALSO

Expand Down
27 changes: 22 additions & 5 deletions jasspa/macros/me.ehf
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,7 @@ 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-format(3)lmpy-format(3)le Format Python source code using either black or yapf
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
Expand Down Expand Up @@ -2708,6 +2709,7 @@ 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-format(3)lmpy-format(3)le Format Python source code using either black or yapf
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
Expand Down Expand Up @@ -3852,6 +3854,7 @@ 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-format(3)lmpy-format(3)le Format Python source code using either black or yapf
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
Expand Down Expand Up @@ -42933,34 +42936,48 @@ $a

lsr(9)lmr(9)le
! 3 py-doc
! 3 py-format
cEcENAME cEcA


|pydoc
|py-doc
py-doc - display documentation for Python modules and packages
|py-format
py-format - format Python source code using either black or yapf
$a

cESYNOPSIS cA

cDpy-doccA ["package|function"]
cDpy-doccA ["package|function"]
cDpy-formatcA

cEDESCRIPTION cA

Displays with the manual page for a Python package module or package.
cDpy-doccA 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.

The cDpy-formatcA macro formats the currently edited file using one of the
Python formatters either cGyapfcA or cGblackcA. You can usually install these
application using your systems package manager or using the pip package
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

py-doc "argparse"
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"

cENOTES cA

cDpy-doccA macro is defined in file cGpytools.emfcA.
The cDpy-doccA and the cDpy-formatcA macros are defined in the file cGpytools.emfcA.

cESEE ALSO cA

Expand Down
4 changes: 2 additions & 2 deletions jasspa/macros/me.emf
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ 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 r-doc
define-macro-file hkpydoc pydoc
define-macro-file rtools r-doc r-format r-lint r-exec
define-macro-file pytools py-doc py-format
define-macro-file zfile find-zfile zfile-setup
define-macro-file gentags generate-tags-file
define-macro-file dmf display-matching-fence
Expand Down
75 changes: 51 additions & 24 deletions jasspa/macros/pytools.emf
Original file line number Diff line number Diff line change
Expand Up @@ -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 : <240925.1607>
; Last Modified : <241220.1806>
;
; Description : Documentation viewer within MicroEmacs for
; Python
Expand All @@ -21,41 +21,41 @@
;


define-macro fhook-pydoc
@# buffer-init "pydoc"
define-macro fhook-py-doc
@# buffer-init "py-doc"
buffer-init-hooks
!emacro

; buffer-init variables
set-variable .fhook-pydoc.name "pydoc"
set-variable .fhook-pydoc.setup &reg "/history/fhook/pydoc" "acfhmw"
set-variable .fhook-pydoc.setup-mask "acfhmw"
set-variable .fhook-py-doc.name "py-doc"
set-variable .fhook-py-doc.setup &reg "/history/fhook/py-doc" "acfhmw"
set-variable .fhook-py-doc.setup-mask "acfhmw"

!if &and &sin "h" .fhook-pydoc.setup &band .hilight.flags 0x02
!iif &not &exi .hilight.pydoc set-variable .hilight.pydoc &pinc .hilight.next 1
0 hilight .hilight.pydoc 0 .scheme.text
hilight .hilight.pydoc 2 "^[A-Z].+" .scheme.header
hilight .hilight.pydoc 2 "^ class" .scheme.keyword
!if &and &sin "h" .fhook-py-doc.setup &band .hilight.flags 0x02
!iif &not &exi .hilight.py-doc set-variable .hilight.py-doc &pinc .hilight.next 1
0 hilight .hilight.py-doc 0 .scheme.text
hilight .hilight.py-doc 2 "^[A-Z].+" .scheme.header
hilight .hilight.py-doc 2 "^ class" .scheme.keyword
!endif

!if &sin "f" .fhook-pydoc.setup
!if &sin "f" .fhook-py-doc.setup
; setup emf collapsing
set-variable .fhook-pydoc.collapse-open "^[A-Z]"
set-variable .fhook-pydoc.collapse-close "^\\([A-Z]\\| class\\|\\'\\)"
set-variable .fhook-pydoc.collapse-mnext "-1"
set-variable .fhook-py-doc.collapse-open "^\\([A-Z]\\| class\\)"
set-variable .fhook-py-doc.collapse-close "^\\([A-Z]\\| class\\|\\'\\)"
set-variable .fhook-py-doc.collapse-mnext "-1"
!endif
; setup item-list
set-variable .fhook-pydoc.item-list-s1 "^\\([A-Z][A-Z]\.+\\)"
set-variable .fhook-pydoc.item-list-r1 "SECT \ecB\\1\ecA"
set-variable .fhook-pydoc.item-list-s2 "^ class +\\([^(]+\\)"
set-variable .fhook-pydoc.item-list-r2 " class \ecB\\1\ecA"
set-variable .fhook-py-doc.item-list-s1 "^\\([A-Z][A-Z]\.+\\)"
set-variable .fhook-py-doc.item-list-r1 "SECT \ecB\\1\ecA"
set-variable .fhook-py-doc.item-list-s2 "^ class +\\([^(]+\\)"
set-variable .fhook-py-doc.item-list-r2 " class \ecB\\1\ecA"

define-macro pydoc
define-macro py-doc
!force set-variable #l0 @1
!if &not $status
set-variable #l0 @ml00 "Python help on"
!endif
0 pipe-shell-command &spr "LANG=en_US pydoc %s" #l0 "*pydoc*"
0 pipe-shell-command &spr "LANG=en_US pydoc %s" #l0 "*py-doc*"
-1 buffer-mode "view"
beginning-of-buffer
3 kill-line
Expand All @@ -68,6 +68,33 @@ define-macro pydoc
!endif
!emacro

add-file-hook "*pydoc*" fhook-pydoc
buffer-init-fhook "pydoc"
ml-write "hkpydoc loaded"
add-file-hook "*py-doc*" fhook-py-doc
buffer-init-fhook "py-doc"

define-macro py-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
!force set-variable #l1 .format
!if &seq #l1 "ERROR"
!if &and &seq &which "yapf" "" &seq &which "black" ""
ml-write "Error: You must have either the black or the yapf formatter installed!"
!abort
!endif
!if &and &seq #l1 "ERROR" &not &seq &which "yapf" ""
set-variable .format "yapf -i"
!else
set-variable .format "black -q"
!endif
set-variable #l1 .format
!endif
2 pipe-shell-command &spr "%s %s" #l1 $buffer-fname "*command*"
!if &equ $result 1
ml-write "Error: It seems that python linters yapf or black are not installed!"
!else
0 reread-file
!endif
!emacro

0 comments on commit bff0f2b

Please sign in to comment.