• 6 Posts
  • 4 Comments
Joined 1 year ago
cake
Cake day: October 17th, 2023

help-circle



  • I made some progress, with read-from-minibuffer the function I need, however I want to terminate the script and suppress the error information at the end.

    ─○ cat text1.txt | emacs -batch --eval "(while t (princ (read-from-minibuffer \"\") (terpri)))"
    
    Here is some text
    Will it be tripled?
    
    Here is some text
    Will it be tripled?
    
    Here is some text
    Will it be tripled?
    Debugger entered--Lisp error: (end-of-file "Error reading from stdin")
      read-from-minibuffer("")
      (princ (read-from-minibuffer "") (terpri))
      (while t (princ (read-from-minibuffer "") (terpri)))
      eval((while t (princ (read-from-minibuffer "") (terpri))) t)
      command-line-1(("--eval" "(while t (princ (read-from-minibuffer \"\") (terpri)..."))
      command-line()
      normal-top-level()
    




  • Here is the solution for my .zsh_history example:

    I first created a small function for the unix time string. More of the functionality in the replacement string can be included if preferred.

        (defun rgx-get-time-string (unixtimestr)
         (format-time-string "%Y-%m-%d %H:%M" (string-to-number unixtimestr))
          )
    

    The search string: \(: \)\([0-9]\{10\}\)\(:0;\)

    The replacement string: \,(concat (format "%6d " (line-number-at-pos)) (rgx-get-time-string (match-string 2)) " "))

    (match-string 2) is an alternative for the back reference for the second string matched\2