Schlagwort-Archive: emacs-lisp

That really was helpful.

I struggled with some “profane” text edit duties, but well, in
over 100 files, and as a programmer … you know what we do.
Spend 3 hours to save repeating a task a few hundred times 😉

My problem, I had to match [[SomeContent]]
And I had an assoc list

setq 'assoc-listt'(("Key-1", "Value1"
                    ("SomeContent", "Some Link to")

I did not get the regular expression right, ChatGPT did it:

(defun my-function ()
  (interactive)
  (with-temp-buffer
    (insert-file-contents "filename.txt")
    (goto-char (point-min))

    ;; Search and replace
    (while (re-search-forward "\\[\\[\\(.*?\\)\\]\\]" nil t)
      (let* ((match (match-string 1))
             (value (cdr (assoc match some-alist))))
        (when value
          (replace-match (format "[[file://%s][%s]]" value match) nil t nil 1))))))

Just one problem the last 1 , that lead to the non replacement of [[ and]] replace it with zero and you’re fine. With some stuff around, with some saving of buffers, did I get what I wanted.
It’s always nice if you can program your editor, and I doubt there is anything as programmable as an Emacs 😉

Thanks for the fish – ah sorry code …

Genugtuung

Für einige Programmierer. Es gibt eine völlig unterschätzte Sprache, Lisp in diversen Varianten. Ein Beispiel was ein Lisp kann, aber nicht viele andere Sprachen:

(defmacro define-advice (symbol args &rest body)
  "Define an advice and add it to function named SYMBOL.
See `advice-add' and `add-function' for explanation on the
arguments.  Note if NAME is nil the advice is anonymous;
otherwise it is named `SYMBOL@NAME'.

\(fn SYMBOL (WHERE LAMBDA-LIST &optional NAME DEPTH) &rest BODY)"
  (declare (indent 2) (doc-string 3) (debug (sexp sexp body)))
  (or (listp args) (signal 'wrong-type-argument (list 'listp args)))
  (or (<= 2 (length args) 4)
      (signal 'wrong-number-of-arguments (list 2 4 (length args))))
  (let* ((where         (nth 0 args))
         (lambda-list   (nth 1 args))
         (name          (nth 2 args))
         (depth         (nth 3 args))
         (props         (and depth `((depth . ,depth))))
         (advice (cond ((null name) `(lambda ,lambda-list ,@body))
                       ((or (stringp name) (symbolp name))
                        (intern (format "%s@%s" symbol name)))
                       (t (error "Unrecognized name spec `%S'" name)))))
    `(prog1 ,@(and (symbolp advice) `((defun ,advice ,lambda-list ,@body)))
       (advice-add ',symbol ,where #',advice ,@(and props `(',props))))))

Man muß dazu schon, was mir AOP anfangen können, um da mitzuziehen. Und das ist Standard in so gut wie jedem Lisp. Im Beispiel ist es Emacs-Lisp eine Programmiersprache so alt wie der Emacs selber, also seit 1984 (und das sind nun 2023 – 1984 = 39 Jahre). Und Lisp ist noch älter, es war immer schon eine programmierbare Programmiersprache. Neue spezielle Schleifen – check. Einseitige Fallunterscheidungen wie when und unless – check.

Viele lachen über Lisp, aber nur noch wenige wissen, was Lisp Machines waren und was die boten.

Lispprogrammierer kann man mit Liberalen in der Politik vergleichen 😉