0

I need to write a command which will apply to my buffer custom, predefined copy-and-replace sequence.

What I have is:

(defun custom-processor ()
  "Formats logs to human-readable format"
  ((replace-in-the-buffer "\n" "\n\n\n")
   (replace-in-the-buffer "\t" "\n")))

(defun replace-in-the-buffer (from to)
  "Replaces in the current buffer all occurences of from to to (not interactively)"
  (while (re-search-forward from nil t)
    (replace-match to nil nil)))

It is basically working for simple characters like letters or numbers, but the case is I need to use it with new lines (\n) and tabs (\t) - the error I get is:

Debugger entered--Lisp error: (invalid-function (replace-in-the-buffer "\n" "\n\n\n"))
  ((replace-in-the-buffer "\n" "\n\n\n") (replace-in-the-buffer "\011" "\n"))
  custom-processor()
  eval((custom-processor) nil)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

I use EMACS for 10y+ but now just starting to leverage it with Lisp programming. Please help.

2
  • This is a duplicate question, but I don't have time now to find the duplicate. Emacs Lisp is a "Lisp 2". When evaluating (<something> ...), something must be a lambda expression or a named function. Your (replace-in-the-buffer "\n" "\n\n\n") is neither.
    – Drew
    Jun 2, 2020 at 16:42
  • I'm hoping someone finds the duplicate - I saw one recently, so people can vote to close. Thx.
    – Drew
    Jun 2, 2020 at 16:44

1 Answer 1

0

Double parenthesis are the culprit.

I guess you forgot to type progn

(defun custom-processor ()
  "Formats logs to human-readable format"
  (progn 
    (replace-in-the-buffer "\n" "\n\n\n")
    (replace-in-the-buffer "\t" "\n")))

or just remove them:

(defun custom-processor ()
  "Formats logs to human-readable format"
  (replace-in-the-buffer "\n" "\n\n\n")
  (replace-in-the-buffer "\t" "\n"))
2
  • thanks for answering - however - can you please advice with one more thing: I cannot find how to replace-in-the-buffer TAB character for sth else. The \t doesn't work. Can you help?
    – supertramp
    Aug 20, 2020 at 8:55
  • Cannot reproduce that behavior evaluating the provided code. Work as intended.
    – Muihlinn
    Aug 20, 2020 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.