Xah Talk Show 2025-07-09 Ep677 Lisp, Code Style, Formatting, Artificial Intelligence and Proof System

xah talk show ep677 2025-07-09 trbfm
xah talk show ep677 2025-07-09 trbfm

timestamp


xah talk show ep677 2025-07-09 2055c
xah talk show ep677 2025-07-09 2055c
(defun xah-update-code-to-website ()
  "Update current defun or defvar to the corresponding website.
i.e. copy the current defun, find the corresponding website local URL file path, update the code in that file in the HTML pre tag.

URL `http://xahlee.info/talk_show/xah_talk_show_ep677.html'
Created: 2025-07-09
Version: 2025-09-26"
  (interactive)
  (let (xbeg xend xbody xfnname xurl)
    (seq-setq
     (xbeg xend)
     (cond
      ((or (eq major-mode 'xah-elisp-mode)
           (eq major-mode 'emacs-lisp-mode))

       ;; (backward-up-list 100 t t)
       ;; (forward-sexp )
       ;; (indent-sexp)

       (let ((xbounds (bounds-of-thing-at-point 'defun))) (list (car xbounds) (cdr xbounds)))
       ;; (list (re-search-backward "(defun \\|(defvar ") (progn (forward-sexp) (point)))
       )
      ;; ((or (eq major-mode 'xah-powershell-mode)
      ;;      (eq major-mode 'powershell-mode))
      ;;  (message "PowerShell mode found ")
      ;;  (let (aa bb)
      ;;    (re-search-backward "^function ")
      ;;    (setq aa (point))
      ;;    (search-forward "{")
      ;;    (goto-char (match-beginning 0))
      ;;    (forward-sexp)
      ;;    (setq bb (point))
      ;;    (list aa bb)))

      (t (error "%s error, not a lisp file." this-command)))
     ;;
     )
    (when (or (not xbeg) (not xend)) (error "error. xah-update-code-to-website, finding start and end position of function failed. xbeg xend are %s %s" xbeg xend))
    (setq xbody (buffer-substring-no-properties xbeg xend))
    (setq xfnname
          (progn
            (goto-char xbeg)
            (re-search-forward "(\\(?:defun\\|defvar\\) +\\([-A-Za-z0-9]+\\)[ \n]" (+ xbeg 100))
            (match-string 1)))
    (when (not xfnname) (error "xfnname %s" xfnname))
    (setq xurl
          (progn
            (goto-char xbeg)
            (if (re-search-forward "[ \n]URL `\\(http://[_./A-Za-z0-9-]+\.html\\)'" xend)
                (match-string 1)
              (error "%s error. url not found." this-command))))
    (let ((xfpath (xah-html-http-to-fpath xurl)))
      (find-file xfpath)
      (when (buffer-modified-p) (save-buffer))
      (let ((xtimestamp (format-time-string "%Y%m%d%H%M%S")))
        (let ((xbackupName (concat buffer-file-name "." xtimestamp "~")))
          (copy-file buffer-file-name xbackupName t)
          (message "\nBackup saved at: %s" xbackupName)))

      ;; (xah-html-dehtmlize-pre-tags)
      ;; (xah-html-rehtmlize-precode-buffer)

      (let ((xfound nil))
        (goto-char (point-min))
        (while (and (not xfound)
                    (search-forward "<pre class=\"emacs-lisp\">" nil :move))
          (let ((xopen-tag-beg (match-beginning 0))
                (xopen-tag-end (match-end 0))
                xclose-tag-beg
                xclose-tag-end)

            (progn
              (goto-char xopen-tag-beg)
              (xah-html-skip-tag-forward)
              (setq xclose-tag-end (point))
              (search-backward "<")
              (setq xclose-tag-beg (point)))

            (goto-char xopen-tag-end)
            (if (search-forward
                 (concat ">" xfnname "<")
                 (min (+ xopen-tag-end 300) xclose-tag-beg)
                 :move)
                (progn
                  (setq xfound t)
                  (delete-region xopen-tag-end xclose-tag-beg)
                  (insert
                   (xah-html-htmlize-string xbody 'xah-elisp-mode)))
              (goto-char xclose-tag-end))))
        (when (not xfound) (error "%s error. not found %s" this-command xfnname)))
      (xah-html-update-article-timestamp)))
  (save-buffer))