• elisp question

    From Cecil Westerhof@Cecil@decebal.nl to gnu.emacs.help on Thu Dec 15 03:54:27 2022
    From Newsgroup: gnu.emacs.help

    When I do:
    (setq pip-version (shell-command-to-string "pip3 --version"))

    pip-version contains:
    "pip 22.3.1 from /usr/local/lib/python3.9/dist-packages/pip (python 3.9)
    "

    How do I get the fourth word with the characters after the last /
    removed? (/usr/local/lib/python3.9/dist-packages/)
    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Axel Reichert@mail@axel-reichert.de to gnu.emacs.help on Thu Dec 15 09:16:23 2022
    From Newsgroup: gnu.emacs.help

    Cecil Westerhof <Cecil@decebal.nl> writes:

    When I do:
    (setq pip-version (shell-command-to-string "pip3 --version"))

    pip-version contains:
    "pip 22.3.1 from /usr/local/lib/python3.9/dist-packages/pip (python 3.9)
    "

    How do I get the fourth word with the characters after the last /
    removed? (/usr/local/lib/python3.9/dist-packages/)

    (file-name-directory (nth 3 (split-string pip-version)))

    See

    https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Name-Components.html
    https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Strings.html
    https://www.gnu.org/software/emacs/manual/html_node/elisp/List-Elements.html

    The Emacs Lisp documentation is great, but for non-Lispers it might be a
    rough ride initially.

    https://www.gnu.org/software/emacs/manual/eintr.html

    will get you started. Have fun learning an old, but great language!

    Axel
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Cecil Westerhof@Cecil@decebal.nl to gnu.emacs.help on Thu Dec 15 12:40:42 2022
    From Newsgroup: gnu.emacs.help

    Axel Reichert <mail@axel-reichert.de> writes:

    Cecil Westerhof <Cecil@decebal.nl> writes:

    When I do:
    (setq pip-version (shell-command-to-string "pip3 --version"))

    pip-version contains:
    "pip 22.3.1 from /usr/local/lib/python3.9/dist-packages/pip (python 3.9) >> "

    How do I get the fourth word with the characters after the last /
    removed? (/usr/local/lib/python3.9/dist-packages/)

    (file-name-directory (nth 3 (split-string pip-version)))

    That works. I tried split-string in the eshell, but got:
    (#("pip" 0 3
    (escaped t))
    #("22.3.1" 0 6
    (escaped t))
    #("from" 0 4
    (escaped t))
    #("/usr/local/lib/python3.9/dist-packages/pip" 0 42
    (escaped t))
    #("(python" 0 7
    (escaped t))
    #("3.9)" 0 4
    (escaped t)))

    So I thought it did not work, but it seems eshell does not work the
    same as elisp.


    See

    https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Name-Components.html
    https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Strings.html
    https://www.gnu.org/software/emacs/manual/html_node/elisp/List-Elements.html

    The Emacs Lisp documentation is great, but for non-Lispers it might be a rough ride initially.

    https://www.gnu.org/software/emacs/manual/eintr.html

    will get you started. Have fun learning an old, but great language!

    I will dive into it.
    Thanks.
    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Cecil Westerhof@Cecil@decebal.nl to gnu.emacs.help on Thu Dec 15 17:14:05 2022
    From Newsgroup: gnu.emacs.help

    Axel Reichert <mail@axel-reichert.de> writes:

    Cecil Westerhof <Cecil@decebal.nl> writes:

    When I do:
    (setq pip-version (shell-command-to-string "pip3 --version"))

    pip-version contains:
    "pip 22.3.1 from /usr/local/lib/python3.9/dist-packages/pip (python 3.9) >> "

    How do I get the fourth word with the characters after the last /
    removed? (/usr/local/lib/python3.9/dist-packages/)

    (file-name-directory (nth 3 (split-string pip-version)))

    See

    https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Name-Components.html
    https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Strings.html
    https://www.gnu.org/software/emacs/manual/html_node/elisp/List-Elements.html

    The Emacs Lisp documentation is great, but for non-Lispers it might be a rough ride initially.

    https://www.gnu.org/software/emacs/manual/eintr.html

    will get you started. Have fun learning an old, but great language!

    Created this function:
    ;; check used characters
    (defun dcbl-get-pip-info (&optional package blocking-package)
    (setq pip "pip"
    lastpart ".dist-info/METADATA")

    (setq pip-version-information (split-string (shell-command-to-string
    "pip --version"))
    pip-command (nth 0 pip-version-information)
    pip-version (nth 1 pip-version-information)
    pip-path (file-name-directory
    (nth 3 pip-version-information)))
    (if (not package)
    (if (not blocking-package)
    (find-file-read-only (concat pip-path pip-command "-" pip-version
    lastpart))
    (error "When package is nil blocking-package should also be nil"))
    (setq package-version (nth 3 (split-string (shell-command-to-string
    "pip show requests"))))
    (find-file-read-only (concat pip-path package "-" package-version
    lastpart))
    (if blocking-package
    (search-forward blocking-package))
    ))

    I wanted to know why a blocking-package blocked a package from being
    installed, but then thought it is also interesting to get information
    about the package and pip. So I also created the other two.

    If the code can be optimised I do not mind to hear that.

    I still have to check that package and blocking-package do not contain
    wrong characters. But I think I will manage that.
    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof
    --- Synchronet 3.21d-Linux NewsLink 1.2