Wednesday, April 8, 2026

Setting file times in Emacs from Time-stamps in file, or "Created " at start of a file: Generated through Google AI Summary

 I do not like AI, but the sheer convenience of it has grabbed my attention.  For tweaking my GNU/Linux system, the answers come in a few seconds, saving me sometimes hours of searching.  

 

Today I realized I had copied files from another system without specifying to save file metadata.  Could I set the file times of files with timestamps using the "Time-stamp: < >" utility in Emacs?   I searched, and, I must freely admit, I asked for more info from the AI helper of Google Search.  After about 7 or more rounds of providing feedback about  a regular expression that did not work, these functions were provided.  Wow.   The last two of these is probably sufficient for my needs.  I will change the names.

 

(defun my/set-file-time-final ()
  "Sets file time by finding 'Time-stamp' and extracting only the date/time.  From Google AI."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    ;; 1. Find the literal word "Time-stamp" anywhere (ignores #, brackets, etc.)
    (if (re-search-forward "Time-stamp" nil t)
        ;; 2. Look for the first date pattern (YYYY-MM-DD HH:MM:SS) that follows it
        (if (re-search-forward "\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}[ T][0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}\\)" nil t)
            (let* ((ts-string (match-string 1))
                   (parsed (parse-time-string ts-string))
                   (lisp-time (when parsed (encode-time parsed))))
              (if (and (buffer-file-name) lisp-time)
                  (progn
                    (set-file-times (buffer-file-name) lisp-time)
                    (message "Success! Mtime set to %s (Username ignored)" ts-string))
                (error "Parsed '%s' but system couldn't use it" ts-string)))
          (error "Found 'Time-stamp' but no YYYY-MM-DD HH:MM:SS format found after it"))
      (error "The word 'Time-stamp' is missing from this file"))))

(defun my/dired-set-times-from-stamps ()
  "In Dired, run 'my/set-file-time-final' on all marked files. From Google AI."
  (interactive)
  (let ((files (dired-get-marked-files)))
    (dolist (file files)
      (with-current-buffer (find-file-noselect file)
        (condition-case err
            (progn
              (my/set-file-time-final)
              (save-buffer))
          (error (message "Skipping %s: %s" file (error-message-string err))))))
    (revert-buffer) ; Refresh the Dired buffer to show the new times
    (message "Done processing marked files.")))

(defun my/dired-set-times-from-stamps ()
  "In Dired, sync system times for marked files. Files without stamps are ignored."
  (interactive)
  (let ((files (dired-get-marked-files))
        (skipped 0)
        (updated 0))
    (dolist (file files)
      (with-current-buffer (find-file-noselect file)
        ;; Use condition-case to catch files that don't have the stamp
        (condition-case nil
            (progn
              (my/set-file-time-final)
              (save-buffer)
              (setq updated (1+ updated)))
          (error (setq skipped (1+ skipped))))))
    (revert-buffer)
    (message "Done! Updated: %d | Skipped (no stamp): %d" updated skipped)))

(defun my/set-file-time-final ()
  "From Google AI summary session after Google search.  Sets file time from header. Handles: Created YYYY-MM-DD Day HH:MM:"
  (interactive)
  (save-excursion
    (goto-char (point-min))
    ;; 1. Search for 'Time-stamp' or 'Created'
    (if (re-search-forward "\\(Time-stamp\\|Created\\):?" nil t)
        ;; 2. Match the date (YYYY-MM-DD) 
        ;;    Then skip any day-of-week (like Tue)
        ;;    Then grab the time (HH:MM or HH:MM:SS)
        (if (re-search-forward "\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)[^0-9]*\\([0-9]\\{2\\}:[0-9]\\{2\\}\\(?::[0-9]\\{2\\}\\)?\\)" nil t)
            (let* ((date-part (match-string 1))
                   (time-part (match-string 2))
                   (ts-string (concat date-part " " time-part))
                   (parsed (parse-time-string ts-string))
                   (lisp-time (when parsed (encode-time parsed))))
              (if (and (buffer-file-name) lisp-time)
                  (progn
                    (set-file-times (buffer-file-name) lisp-time)
                    (message "Success! Mtime set to %s" ts-string))
                (error "Parsed '%s' but couldn't use it" ts-string)))
          (error "Found keyword but date/time format was unexpected"))
      (error "No 'Time-stamp' or 'Created' header found"))))

(defun my/dired-set-times-from-stamps ()
  "From Google AI summary session.  This calls the function my/set-file-time-final.  In Dired, sync system modification times for all marked files
based on the 'Created' or 'Time-stamp' lines inside them."
  (interactive)
  (let ((files (dired-get-marked-files))
        (updated 0)
        (skipped 0))
    (dolist (file files)
      ;; Open the file in a buffer without switching to it
      (with-current-buffer (find-file-noselect file)
        (condition-case nil
            (progn
              ;; Call your working 'within-the-file' function
              (my/set-file-time-final)
              ;; Save the buffer to ensure metadata is flushed to disk
              (save-buffer)
              (setq updated (1+ updated)))
          (error 
           (setq skipped (1+ skipped))))))
    ;; Refresh the Dired buffer so you see the new dates immediately
    (revert-buffer)
    (message "Batch complete: %d updated, %d skipped (no stamp found)." updated skipped)))

(with-eval-after-load 'dired
  (define-key dired-mode-map (kbd "T") 'my/dired-set-times-from-stamps))

Wednesday, March 18, 2026

Shinestacker for focus stacking

 This is the first image I processed using Shinestacker.  It's a remarkable and technically advanced piece of open source software.    This software is beyond my skill level, but works incredibly well with defaults.  

 

Sufficeth to say it was very simple, after a somewhat convoluted---but not difficult---installation on CachyOS, to process this stack of 40 images.  I have a CPU with 27 or 28 processors; and this software even took advantage of my aging Nvidia GTX-1050 video card with a mere 3GB of video ram.  25X objective, mounted in UV-curing glass glue from a hardware store.  Too bad about the detritus.  Processing took a few seconds.  


 

Ossicles of Holothuria atra mounted in UV-curing glass glue.

 

Actually, Wayland is usable. I am leaning on Sway on my laptop.

 Just to bring the conversation up to date.

 

 

Thursday, February 12, 2026

Wayland is not happening for me

Due to issues with HiDPI (High Dots-Per-Ince) on my Lenovo Thinkpad X1 Carbon, I wanted to try Sway and Hyprland, which were touted to handle HiDPI displays transparently.   The original issue was mainly that my go to i3 tiling window manager does not pay well with HiDPI resolution.  Text was unreadable for some apps.   

 It is true.  Out of the box, Sway---especially installed as a complete distribution of Manjaro Sway Edition---worked nicely.  Many key bindings were compatible with i3.  In a day or two, I was up and running.  

Along the way, I tried Hyprland, an overly decorated tiling option.  Hyprland works really well.  It was able to run applications like RawTherapee that did not work well for me on the Sway install.  Even the flatpak of Entangle Photo Manager---an essential package for me---worked well.  Not so for Sway.  Today I found an application that does not work with Hyprland, either.  

 I have maintained i3 on my desktop linux box.   It seemed ok to use either of the two Wayland options on my laptop; but jumping from system to system is too painful, when some apps don't work on one, but work fine on the other.  

 Wayland has some downsides, imho.  Configuration is a little too nerdy.  

 When wayland first arrived on the scene, I wondered what could be so bad about X11 that these changes were needed.  I'm getting tired of jumping through update hoops; that's why I quit Gentoo a long time ago.   I now learn that Wayland, slick as it may be, is actually not a drop-in replacement for X11, which I am now used to.

 Apparently Xwayland, often mentioned as a way to run X11 applications on Wayland machines, is not as simple to use as promised by Sway users.  There are some other issues, that apparently X11 compatibility do not solve.  I have not figured out how to configure Xwayland on Sway.   

 Goodbye, Wayland, at least for now.   Maybe I'll try you again, someday.  But why?

 

 

Thursday, February 5, 2026

Trying out Sway, an i3wm workalike for Wayland

 A good move I recently made was to sell my MacBook Pro, M2; and purchase a Lenovo Thinkpad X1 Carbon, several years old.  One of the best features of this new laptop is a HiDPI (High Dots Per Inch) screen with a resolution of something like  3200x1800.  It's a remarkable display for other reasons, which I will not go into here.  The blacks are incredible.  

 With my usual Manjaro i3wm, this means that the type is almost unreadable.  With the guidance of several source on the Internet, I was able to cajol the system into somewhat useful settings that most software works fine with.  Along they way, several references passed me by about Wayland, a newer graphical setup that X11.  

 

I am reluctant to make huge changes to a long time stalwart system, but finally I have begun to experiment with Sway, a workalike system to i3, and Hyprland, a fancier tiling window manager, working on top of Wayland.  Both, I am happy to report, work nicely with this  HiDPI screen.  

 

So I installed Manjaro's Sway edition.  So far, so good.  Now I'm at the point of trying to configure pop-up/drop-down floating windows for Kitty, Emacs, R, orage (probably impossible, but this is the best little calendar app I have found.  Once I have set the month, and popped it back up, the same month is show.  Very useful for calendar work), and a ham radio clock, that is actually of little use.  

HiDPI is not a problem.  

 

When I install a new distro, one of the first things I do  is set the user id to "1004", as well as the groupid.  Consequently, the home directory of my previous setup and user are completely accessible, because this was the case for the previous login as well.  I never duplicate the login, out of worry that the dot file tweaks will be incompatible with anything different.  

 

So far, so good.

 

Setting file times in Emacs from Time-stamps in file, or "Created " at start of a file: Generated through Google AI Summary

 I do not like AI, but the sheer convenience of it has grabbed my attention.  For tweaking my GNU/Linux system, the answers come in a few se...