reddit / emacs
Repository with code snippets and utility functions
mmontone · 2022-09-14 13:44
Hello.
I've been thinking of a repository/database with snippets of code for Emacs. With utility functions and commands we put in .emacs, but are not big enough to put in a library. Centralized, classified, tagged, browsable from Emacs, maybe the web too.
Is this a good idea? Is there something like that already? If not, do you have ideas on how to implement?
I know there's the EmacsWiki, but it's not quite the thing I'm looking for.
Thanks.
orzechod · 2022-09-14 13:53
could you explain a little why EmacsWiki isn't what you are looking for? it's what I would have recommended had you not written that last sentence :)
mmontone · 2022-09-14 14:01
I know it may be close, but, let's say I have a couple of functions in my .emacs. I have an \`apropos-package\` and \`ert-run-test-at-point\` commands that I've implemented. I would like to publish them somehow. Not big enough to make a library. Is a wiki page the optimal place? So, I'm thinking that if we had a database with functions and commands, that is categorized and browsable, then I could add there. And then trigger a search from my emacs, with 'package' or 'ert', and then those functions would appear.
I think it is a problem of granularity. I want to be able to classify and browse things at the function/command level.
deaddyfreddy · 2022-09-14 14:20
> Not big enough to make a library.
A lot of packages on MELPA consist of a couple of functions, so I don't see a problem here. Besides that, you can just put your custom functions to a single package, like:
https://github.com/alphapapa/unpackaged.el
https://github.com/bbatsov/crux
> Is a wiki page the optimal place?
I don't think so, using `git` is a better solution IMO
mmontone · 2022-09-14 14:28
>A lot of packages on MELPA consist of a couple of functions, so I don't see a problem here. Besides that, you can just put your custom functions to a single package, like:
>
>[https://github.com/alphapapa/unpackaged.el](https://github.com/alphapapa/unpackaged.el)
>
>[https://github.com/bbatsov/crux](https://github.com/bbatsov/crux)
But that has a discoverability problem. I would like to trigger a search from Emacs and functions from a centralized repository appear.
I could create a github gist and put my functions there, but I'm looking for better than that.
deaddyfreddy · 2022-09-14 14:47
> But that has a discoverability problem. I would like to trigger a search from Emacs and functions from a centralized repository appear.
sure, but:
- it has a decent search (so you can do something "(require 'erc) defun erc- language:elisp")
- there's already a lot of Elisp code (more than any custom service will have in the nearest future).
So the task here is not to invent wheels, but to smartly index elisp related stuff based on what we already have.
An alternative source is MELPA repo, every package there has a link to a repo, so you can download every package and index them. But this will work only for packages there.
mmontone · 2022-09-14 15:22
Those are good points. But, I'm not interested in indexing elisp in already existing packages in MELPA. I'm more interested in indexing stuff that's difficult to justify creating a package for. For example, in my view, those 'unpackaged' and 'crux' names are very generic and it is because what's inside is generic too, does not belong to packages per se.
A "MELPA-snippets" repo + services is what I would like to have.
00-11 · 2022-09-14 16:01
> I would like to publish them somehow. Not big enough to make a library. Is a wiki page the optimal place?
Optimal in what way? What are your reservations/hesitations wrt the wiki? It's a pretty good place to search for and find those kinds of things, I think. And unlike "package" there's no real definition of a "library" - it's essentially a file of Elisp code.
You can also "publish" the things you mention here in Reddit. Or on your own website. You can create your own page(s) on EmacsWiki and link to all of your snippets from there (the code being in the wiki's Elisp section).
You don't really say anything about the purposes for which you would "publish", how (or even whether) you would like others to discover them or use them, etc. Where you "publish" depends, I'd think, on what you want to happen to/with what you publish.
BillDStrong · 2022-09-14 20:04
Wouldn't a custom github/lab/gist etc search give you a lot of what you want in discoverability? Then you can just publish to github, and bam, you are done.
mmontone · 2022-09-14 20:11
That may be a good idea to try. I'll give it a shot soon.
Also, I'm considering trying an experiment: create a git repository with elisp files, and index them, at the function level. There are some pieces already in place in `package` and `lisp-mnt` packages.
arthurno1 · 2022-09-14 20:56
> I would like to publish them somehow. Not big enough to make a library. Is a wiki page the optimal place?
Why would it not be? You can publish here on Reddit if you really itch for publishing. Just make a thread for each one. Or even better, [there is a weekly tips & tricks thread](https://www.reddit.com/r/emacs/comments/xdw6ok/weekly_tips_tricks_c_thread/). Anyone searching the web for "ert" or "package" will get hits :).
> I want to be able to classify and browse things at the function/command level.
Name your functions something with "package-" and "ert-" prefixes and whey you complete functions names they will pop up in candidates (if you use some completion framework such as Helm).
You can also make a package for each, with a good description, and publish in Melpa, and then you can search and browse them with 'list-packages'.
BillDStrong · 2022-09-14 23:25
Actually, now that I am thinking about it, you could essentially turn all of GitHub into a wiki for emacs if you create a function that searches for a specially named org file, and just let anyone that wants their code included into the wiki to put one into their repository.
This allows you to have the best of both worlds, and frees you from having to manage it, right? You just need a set of basic info to search for, and a version spec number, and then a plain org file that has the info inside it.
Oh, and maybe a lang tag as well. If it takes off in elisp, other languages will want it too.
Mind you, this may not be what you actually want, however.
mmontone · 2022-09-14 23:55
Interesting. I'm thinking that, perhaps, the Emacs package format (header, commentary, keywords, author, code), would be good for my idea of snippets too. But I don't like the idea of publishing snippets that containe a single function to MELPA, which is a curated package manager. So, I like your idea of "scraping" Github, etc. I'm thinking that I could look for specific files, as you suggest. I could look for files with some extension, let's say '.snippet.el'; github provides a query for that: https://github.com/search?q=.el+in%3Apath&type=Code . Then use that to create an index, that can be browsed, searched, classified, etc.
BillDStrong · 2022-09-15 00:25
An advantage of a specific format is the authors can classify it themselves in the org files. You can just pick that out.
You could piggyback off of Melpa, they already have a useful format for some of what you want.
[Melpa Recipe Format.](https://github.com/melpa/melpa/blob/master/README.md#recipe-format)
You can also just ask devs to add the meta date to the Elisp file itself.
You could use Melpa and El-get as a search source if you want to use the same system for larger projects later.
Essentially creating a huge wiki for all Emacs packages.
Probably out of scope, of course.
mmontone · 2022-09-15 00:45
>An advantage of a specific format is the authors can classify it themselves in the org files. You can just pick that out.
>
>You could piggyback off of Melpa, they already have a useful format for some of what you want.
>
>Melpa Recipe Format.
>
>You can also just ask devs to add the meta date to the Elisp file itself.
>
>You could use Melpa and El-get as a search source if you want to use the same system for larger projects later.
Yes. What I'm pointing out is that elisp package files already contain pretty much all information I would want. This: https://www.gnu.org/software/emacs/manual/html\_node/elisp/Library-Headers.html
>Essentially creating a huge wiki for all Emacs packages.
Your idea of using org is better for a wiki, because of the richer formatting. I could also mix-in org formatting in `;;; Commentary:`, to get rich formatting for the description of the snippets, and standard package format for the files. Also, instead of looking for a particular file extension, I can look for normal package files, but index those that contain 'snippet' as one of their keywords.
deaddyfreddy · 2022-09-15 08:31
> I'm more interested in indexing stuff that's difficult to justify creating a package for.
no one stops you from creating a package containing even a single function
mmontone · 2022-09-15 13:02
Is it possible to access the EmacsWiki elisp area as a package-archive from Emacs?
https://www.emacswiki.org/emacs?action=elisp-area
mmontone · 2022-09-15 13:33
I've downloaded EmacsWiki archive from here: [https://github.com/varlardohaeris/emacs-archives/tree/master/emacswiki](https://github.com/varlardohaeris/emacs-archives/tree/master/emacswiki)
Then added to `package-archives`:
```lisp
(add-to-list 'package-archives '("emacswiki" . "/home/marian/src/emacswiki/"))
```
Now I can browse EmacsWiki Elisp files from Emacs, using `package-list-packages` and friends.
mmontone · 2022-09-15 15:47
Even better, it is possible to add hosted git repositories as Emacs package-archives, like this for example:
```lisp
(add-to-list 'package-archives '("emacs-snippets" . "https://codeberg.org/mmontone/emacs-snippets/raw/branch/master/"))
```
Or this for EmacsWiki elfiles:
```lisp
(add-to-list 'package-archives '("emacswiki" . "https://raw.githubusercontent.com/varlardohaeris/emacs-archives/master/emacswiki/"))
```
fragbot2 · 2022-09-16 02:32
I do this with org-roam notes. It makes for a really simple way to keep track of small code snippets and the backlinks and org-roam's graphical capability make it easy to find what you need. Finally, org's native publishing capability makes it trivial to export your notes.