https://github.com/mooerslab/cctbxsnips-emacs
cctbxsnips for the Emacs yasnippet package
https://github.com/mooerslab/cctbxsnips-emacs
atomic-chrome cctbx code-reuse code-snippets code-snippets-python colab crystallographic-computing emacs ghosttext jupyter-notebooks yasnippets
Last synced: 3 months ago
JSON representation
cctbxsnips for the Emacs yasnippet package
- Host: GitHub
- URL: https://github.com/mooerslab/cctbxsnips-emacs
- Owner: MooersLab
- License: mit
- Created: 2023-01-24T13:35:55.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-10T11:50:46.000Z (about 1 year ago)
- Last Synced: 2025-02-07T03:42:06.738Z (4 months ago)
- Topics: atomic-chrome, cctbx, code-reuse, code-snippets, code-snippets-python, colab, crystallographic-computing, emacs, ghosttext, jupyter-notebooks, yasnippets
- Language: YASnippet
- Homepage:
- Size: 43.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cctbxsnips for the yasnippets package in Emacs

[](https://opensource.org/licenses/MIT)## CCTBX
[CCTBX](https://github.com/cctbx/cctbx_project) is the Computational Crystallography Toolbox.
Its development is based at Lawrence-Berkeley National Laboratory.
It provides code for computations with diffraction data and atomic coordinates of proteins and small molecules.
It has C++ and Python ports.
It is available in Anaconda in the conda-forge channel as *cctbx-base* for python3.8 through 3.11 for Windows, macOS, and Linux.### Blaine's cctbx install protocol
I assume that Anaconda has already been installed. We also create the Jupyter notebook kernel while we are at it. Execute one line at a time: Wait for the execution to finish before executing the next line.
```bash
conda create --name cctbx39 python=3.9
conda activate cctbx39
conda install -c conda-forge cctbx-base -y
conda install ipykernel -y
python -m ipykernel install --user --name cctbx39 --display-name "cctbx python3.9"
```The second to last command triggers the installation of Jupyter in the cctbx39 env.
The last command creates and installs the Jupyter kernel in `~/Library/Jupyter/kernels/cctbx39` on the Mac.
Select **cctbx python3.9** from the list of kernels when opening a new notebook in Jupyter.Replace the *3.9* or *39* above with whatever version of Python you want to use (between 3.8 and 3.11).
## yasnippets
The yasnippets package is a top-rated snippet manager for Emacs.
There are other snippets managers for Emacs, but yasnippets is very popular.
The yasnippets package is not built into Emacs and must be installed separately.
It is available in MELPA.## The problems that this repo addresses
1. **Facilitation of code reuse**. Code snippets can save time by reusing existing code. The presence of tab stops in code snippets can help ensure that all parameters that need customization to a new problem are considered. Thus, tab stops can reduce subsequent debugging.
2. **Use Emacs to edit Jupyter and Colab code and markdown cells** The existing snippet formats for Jupyter and Colab notebooks do not support tab triggers and tab stops, which are standard features of code snippet systems in most text editors. We can overcome these limitations by sending the active code cell to Emacs via the GhostText extension for the browser and the atomic-chrome package for Emacs.
## Installation
1. Install the snippets
```bash
cd ~/.emacs.d/snippets/python-mode
git clone https://github.com/MooersLab/cctbxsnips-Emacs.git
cd cctbxsnips-Emacs/yasnippets
mv * ../../.
cd ../..
rm -rf cctbxsnips-Emacs
```2. **Optional** If you want to use these snippets from Emacs to edit live cells in Jupyter or Colab notebooks, install [GhostText](https://ghosttext.fregante.com/) in your browser and atomic-chrome in [Emacs](https://github.com/alpha22jp/atomic-chrome).
Below is the related configuration for my Emacs initialization file.
Note that I have set the default programming language scope to Python so that code cells in Jupyter notebooks open in Emacs as being in the *python-mode* were sent to Emacs from the web browser running the Jupyter session.```elisp
;; atomic-chrome, used to interact with GhostText extension for Google Chrome.
(use-package atomic-chrome
:ensure t)
;; uncomment the line below to start the server on start-up of Emacs.
;; (atomic-chrome-start-server)
(setq atomic-chrome-default-major-mode 'python-mode)
(setq atomic-chrome-extension-type-list '(ghost-text))
;;(atomic-chrome-start-httpd)
(setq atomic-chrome-server-ghost-text-port 4001)
(setq atomic-chrome-url-major-mode-alist
'(("github\\.com" . gfm-mode)
("overleaf.com" . latex-mode)
("750words.com" . latex-mode)))
; Select the style of opening the editing buffer by atomic-chrome-buffer-open-style.
; full: Open in the selected window.
; split: Open in the new window by splitting the selected window (default).
; frame: Create a new frame and window in it. You must be using some windowing package.
(setq atomic-chrome-buffer-open-style 'split)
```## Example of use
Note that the user experience will vary widely with regards to autocompletion and the use of the yasnippets package depending on how Emacs has been configured.
I use Gnu Emacs configured from scratch.## Related repositories
- [cctbxsnips-SublimeText3](https://github.com/MooersLab/cctbxsnips-SublimeText3) CCTBX snippets for Sublime Text 3 (ST3).
- [cctbxsnips-VSC](https://github.com/MooersLab/cctbxsnips-VSC) CCTBX snippets for Visual Studio Code (VSC).
- [cctbxsnips-UltiSnips](https://github.com/MooersLab/cctbxsnips-Ultisnips) CCTBX snippets for Vim or NeoVim via UltiSnips plugin.
- [cctbxsnips-neosnippets](https://github.com/MooersLab/cctbxsnips-neosnippets) CCTBX snippets for Vim or NeoVim via neosnippets plugin.
- [cctbxsnips-Snipmate](https://github.com/MooersLab/cctbxsnips-snipmate) CCTBX snippets for Vim or NeoVim via snipmate plugin.
- [cctbxsnips-Atom](https://github.com/MooersLab/cctbxsnips-Atom) CCTBX snippets for Atom.- [Jupyterlab cctbx snippets](https://github.com/MooersLab/jupyterlabcctbxsnips) CCTBX snippets for JupyterLab with the jupyterlab-snippets extension or the jupyterlab-snippets-mutlimenus extension.
- [Jupyterlab cctbx plus snippets](https://github.com/MooersLab/jupyterlabcctbxsnipsplus) The variant of the jupyterlabcctbxsnips library with comments to guide editing of the snippets.
- [Colab cctbx snippets](https://github.com/MooersLab/colabcctbxsnips) Colab snippets.## Update History
|Version | Changes | Date |
|:-----------:|:-----------------------------------------------:|:---------------:|
| Version 0.2 | Fixed typos in README.md | 2024 April 10 |## Sources of funding
- NIH: R01 CA242845
- NIH: R01 AI088011
- NIH: P30 CA225520 (PI: R. Mannel)
- NIH P20GM103640 and P30GM145423 (PI: A. West)