Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QE-modes installatio with straight.el. #871

Closed
hongyi-zhao opened this issue Oct 22, 2021 · 17 comments
Closed

QE-modes installatio with straight.el. #871

hongyi-zhao opened this issue Oct 22, 2021 · 17 comments
Labels

Comments

@hongyi-zhao
Copy link

hongyi-zhao commented Oct 22, 2021

The QE-modes package is an open-source collection of Emacs major-modes for making the editing of Quantum ESPRESSO input files somewhat easier and more comfortable with Emacs editor.

I would like to know how to use straight.el to install and manage it.

Regards,
HZ

@progfolio
Copy link
Contributor

I want to know to install and manage it with straight.el.

The following recipe makes use of the :files keyword to properly symlink the package's .el files.
The :includes keyword is used to inform straight-use-package that those packages all live in the same repository and should not be searched for elsewhere if requested.

At a quick glance it looks like there is some unconventional packaging going on in their repo.
They probably shouldn't be distributing compiled elisp files. Those are not guaranteed to be bytecode compatible between Emacs versions and should be generated by the user's Emacs. Straight will handle this properly on its own as well as adding everything to the load-path, generating autoloads, etc.- so you can ignore any instructions they give to do any of that. If you have any questions specific to their build process, you'll have to raise an issue with the authors, as I'm not familiar with this package collection.

(straight-use-package
 '(qe-modes
   :host gitlab
   :repo "QEF/q-e"
   :files ("GUI/QE-modes/qe-modes/*.el")
   :includes
   (cp-mode ld1-mode neb-mode ph-mode pp-mode pw-mode pwtk-mode qe-funcs qe-mode qe-modes)))

Tested with:

Yodel Report (2021-10-24 01:39:05):

(yodel
  :user-dir "qe-test"
  :save t
  :packages*
  (qe-modes
   :host gitlab
   :repo "QEF/q-e"
   :files
   ("GUI/QE-modes/qe-modes/*.el")
   :includes
   (cp-mode ld1-mode neb-mode ph-mode pp-mode pw-mode pwtk-mode qe-funcs qe-mode qe-modes))
  :post*
  (require 'cp-mode))
STDOUT:
Loading /tmp/qe-test/straight-bootstrap-snippet.el (source)...
Bootstrapping straight.el...
Bootstrapping straight.el...done
Rebuilding all packages due to build cache schema change
Looking for gnu-elpa-mirror recipe -> Cloning melpa...
Looking for gnu-elpa-mirror recipe -> Cloning melpa...done
Looking for emacsmirror-mirror recipe -> Cloning gnu-elpa-mirror...
Looking for emacsmirror-mirror recipe -> Cloning gnu-elpa-mirror...done
Looking for emacsmirror-mirror recipe -> Cloning el-get...
Looking for emacsmirror-mirror recipe -> Cloning el-get...done
Looking for straight recipe -> Cloning emacsmirror-mirror...
Looking for straight recipe -> Cloning emacsmirror-mirror...done
Building straight...
Building straight...done
Cloning q-e (for qe-modes)...
Cloning q-e (for qe-modes)...done
Building qe-modes...
Building qe-modes...done
Environment
  • emacs version: GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.17.4, Xaw3d scroll bars)
    of 2021-10-10
  • system type: gnu/linux
Packages
Name Branch Commit Date Source
qe-modes develop 3ec8620fc3 2021-10-24 nil

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Oct 24, 2021

The :includes keyword is used to inform straight-use-package that those packages all live in the same repository and should not be searched for elsewhere if requested.

So, it's used to solve the package dependencies among these modes themselves.

They probably shouldn't be distributing compiled elisp files. Those are not guaranteed to be bytecode compatible between Emacs versions and should be generated by the user's Emacs.

Thank you for pointing this out. I've created a PR here.

   :includes
   (cp-mode ld1-mode neb-mode ph-mode pp-mode pw-mode pwtk-mode qe-funcs qe-mode qe-modes)))

If some modes have been added or removed, the above method will not correctly reflect this situation.

@progfolio
Copy link
Contributor

If some modes have been added or removed, the above method will not correctly reflect this situation.

See previous discussion: #762

The :includes keyword is optional, but if a call to straight-use-package is made (directly or via a use-package expansion) which requests one of those packages, it will fail. You can mitigate this when straight-use-package-by-default is non-nil by setting the use-package :straight keyword to nil in declarations for the included packages. Note this doesn't cover the case of transitive dependencies.

@hongyi-zhao
Copy link
Author

It still looks complicated.

@progfolio
Copy link
Contributor

If you have a better solution, please share it.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Oct 25, 2021

I don't know if we can run lisp code under the :includes keyword to determine/generate the list in real-time. Or perform the job in the :pre-build keyword and assign a variable that can be used by :includes.

@progfolio
Copy link
Contributor

See previous discussion: #762

I've outlined why that is not currently possible there.

@hongyi-zhao
Copy link
Author

(straight-use-package
 '(qe-modes
   :host gitlab
   :repo "QEF/q-e"
   :files ("GUI/QE-modes/qe-modes/*.el")
   :includes
   (cp-mode ld1-mode neb-mode ph-mode pp-mode pw-mode pwtk-mode qe-funcs qe-mode qe-modes)))

I tried the following in my init file:

(use-package qe-modes
  :straight (:host gitlab
		   :repo "QEF/q-e"
		   :files ("GUI/QE-modes/qe-modes/*.el")
		   :includes
		   (cp-mode ld1-mode neb-mode ph-mode pp-mode pw-mode pwtk-mode qe-funcs qe-mode qe-modes)))

The above recipe will compile the el files automatically, but the whole repository, which is a huge project, must be cloned first. I wonder if I can just clone the files straight needs?

@progfolio
Copy link
Contributor

progfolio commented Dec 20, 2021

The above recipe will compile the el files automatically, but the whole repository, which is a huge project, must be cloned first. I wonder if I can just clone the files straight needs?

I cloned the repo and it looks like it's just under 1GB.
A shallow clone was roughly 1/3rd of that size.

Unless you need the full repository history and tags, you can set the recipe :depth keyword for this repository.

See: https://github.com/raxod502/straight.el/tree/develop#git-backend

@hongyi-zhao
Copy link
Author

I tried with the following recipe:

(use-package qe-modes
  :straight (:host gitlab
		   :repo "QEF/q-e"
		   :files ("GUI/QE-modes/qe-modes/*.el")
		   :depth 1
		   :includes
		   (cp-mode ld1-mode neb-mode ph-mode pp-mode pw-mode pwtk-mode qe-funcs qe-mode qe-modes)))

But the size still exceeds 1GB:

$ git log 
commit e94356770b00ef39ca52436b08c144d7cbae30d5 (grafted, HEAD -> develop, origin/develop, origin/HEAD)
Author: giannozz <paolo.giannozzi@uniud.it>
Date:   Sun Dec 19 07:52:36 2021 +0000

    Merge branch 'fix_ipi' into 'develop'
    
    Fix the i-PI communication protocol in run_driver.f90
    
    See merge request QEF/q-e!1677

$ du -d1 -h ~/.emacs.d/straight/repos/q-e/ | tail -1
1.4G	/home/werner/.emacs.d/straight/repos/q-e/

@progfolio
Copy link
Contributor

Apologies. I must've misread my test output. Unfortunately, we don't currently support sparse checkouts, as there is limited forge/git support for it at the moment.

See: https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository

Not much we can do about it if the elisp and the main project are hosted in the same repository.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Dec 20, 2021

Unfortunately, we don't currently support sparse checkouts, as there is limited forge/git support for it at the moment.

See: https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository

I have heard of this feature of git and, IIRC, have also used it before.

Not much we can do about it if the elisp and the main project are hosted in the same repository.

If I understand correctly, currently, the Makefile of this package relies on the main project to build this package: The package can be build by simply running the make command under the directory it resides.

One more thing to note: If we use straight package to install QE-modes, then the configuration in qe-modes.emacs also needs to be added to the recipe of use-package accordingly, as follows:

(use-package qe-modes
  :straight (:host gitlab
		   :repo "QEF/q-e"
		   :files ("GUI/QE-modes/qe-modes/*.el")
		   :depth 1
		   :includes
		   (cp-mode ld1-mode neb-mode ph-mode pp-mode pw-mode pwtk-mode qe-funcs qe-mode qe-modes)))
:config
;; automatic filename recognition
;; (BEWARE: more general patterns must be specified first)

;; automatically open the *.in files with generic QE mode
(add-to-list 'auto-mode-alist '("\\.in\\'" . qe-mode))
;; automatically open the *.pwtk files with generic PWTK/QE mode
(add-to-list 'auto-mode-alist '("\\.pwtk\\'" . pwtk-mode))

;;  automatically open the the pw.*.in, scf.*.in, nscf.*.in, relax.*.in,
;;  vc-relax.*.in, md.*.in, vc-md.*.in files by pw.x mode
(add-to-list 'auto-mode-alist
             '("/\\(pw\\|n?scf\\|\\(?:vc-\\)?\\(?:md\\|relax\\)\\)\\(\\.\\(?:.*\\)?\\)?\\.in\\'" . pw-mode))

;; automatically open the neb.*.in and smd.*.in files with neb.x mode
(add-to-list 'auto-mode-alist '("/\\(neb\\|smd\\)\\(\\.\\(?:.*\\)?\\)?\\.in\\'" . neb-mode))

;; automatically open the cp.*.in files with cp.x mode
(add-to-list 'auto-mode-alist '("/cp\\(\\.\\(?:.*\\)?\\)?\\.in\\'" . cp-mode))

;; automatically open the ph.*.in files with ph.x mode
(add-to-list 'auto-mode-alist '("/ph\\(\\.\\(?:.*\\)?\\)?\\.in\\'" . ph-mode))

;; automatically open the ld1.*.in files with ld1 mode
(add-to-list 'auto-mode-alist '("/ld1\\(\\.\\(?:.*\\)?\\)?\\.in\\'" . ld1-mode))

;; automatically open the pp.*.in files with pp.x mode
(add-to-list 'auto-mode-alist '("/pp\\(\\.\\(?:.*\\)?\\)?\\.in\\'" . pp-mode))


;;; default indentation offset is 3; uncomment below line and set the
;;; value accordingly if you prefer other value
;
;(setq qe-indent 4)


;;; uncomment below lines to disable the auto-indentation ...
;;; ( are you really sure you want to do this ? )
;
;;(dolist (hook '(qe-mode-hook
;;                pw-mode-hook
;;                cp-mode-hook
;;                ph-mode-hook
;;                ld1-mode-hook
;;		  pp-mode-hook))
;;  (add-hook hook (lambda () (setq indent-line-function 'indent-relative))))

@hongyi-zhao
Copy link
Author

Is it possible or there a plan for straight to support such things like git sparse checkout?

@progfolio
Copy link
Contributor

Is it possible or there a plan for straight to support such things like git sparse checkout?

Unfortunately, we don't currently support sparse checkouts, as there is limited forge/git support for it at the moment.

It's a relatively new feature of git itself and from what I understand has limited support on github. So not any time soon.

@hongyi-zhao
Copy link
Author

Another question following-up your above point of view: Is it possible to use the powerful features of elisp, such as the advice function, to implement git sparse checkout in straight-use-package?

@progfolio
Copy link
Contributor

Try it out and let me know.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Dec 20, 2021

But I've no idea what/where/how should I advise straight-use-package, shame on me for my low understanding of straight and elisp. What I think above is just a hunch based on techniques used in past communication on Emacs related issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants