💾 Archived View for gem.librehacker.com › gemlog › starlog › 20240212-0.gmi captured on 2024-06-16 at 12:14:01. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-03-21)

-=-=-=-=-=-=-

Emacs: Starting Gemlog Entries Faster (publ. 2024-02-12)

A great thing about gemtext is it is so simple I don't need a CMS. But it was still taking me a minute or two to create the new gemtext file on the server, as I had to login, navigate to the correct directory, and type a file name with the correct date and sequence number. I use a sequence number in my system in case there is more than one post a day. Naturally, the solution for me was an Emacs function.

Here is the function doing most of the work which finds, over SSH, the next unused path in my file naming scheme:

(defvar gemlog-directory "/ssh:yourdomainhere.example.com:/srv/gemini/gemlog/")

(defun find-unused-gemlog-file (gemlog &optional time)
  "Return a string with the the path <gemlog-directory>/<gemlog>/YYYYMMDD-N.gmi, where the file does not yet exist and N is the lowest whole number possible in the range [0,inf)."
  (let* ((time (if time time (current-time)))
         (prefix (format-time-string "%Y%m%d-" time)))
    (cl-labels ((worker (seqnum)
                   (let ((proposed-path
                          (concat
                           gemlog-directory gemlog "/" prefix (number-to-string seqnum) ".gmi")))
                     (if (file-exists-p proposed-path)
                         (worker (1+ seqnum))
                       proposed-path))))
      (worker 0))))

True lispy recursion going on there. Next is a function that actually creates the file:

(defun make-new-gemlog-file (gemlog)
  "Finds an unused file path using find-unused-gemlog-file and creates and opens it with find-file."
  (find-file (find-unused-gemlog-file gemlog)))

I have several gemlogs, but they are found at the same root directory, so I pass in the name of the specific gemlog directory. Finally I made a convenient interactive function to call it for a specific gemlog:

(defun make-new-starlog-entry ()
  (interactive)
  (make-new-gemlog-file "starlog"))

So, now I just call make-new-starlog-entry (through Helm) to start a new starlog gemlog post. I'm working on another function that will add the entry to the gemfeed index, and some other convenience functions.

Copyright

This work © 2024 by Christopher Howard is licensed under Attribution-ShareAlike 4.0 International.

CC BY-SA 4.0 Deed