help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Printing list to buffer


From: Jean Louis
Subject: Re: Printing list to buffer
Date: Sat, 22 Oct 2022 09:48:37 +0300
User-agent: Mutt/2.2.7+37 (a90f69b) (2022-09-02)

* Heime via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> 
[2022-10-22 02:33]:
> I am using the function to print a lisp object to a buffer, but the printing 
> is not happening.
> 
> I set a list
> 
> (defvar names '("Paul" "Peter"))
> 
> (viewer names)
> 
> --------------------
> 
> (defun viewer (bufrn obj)
> 
> "Prints object obj to a buffer."
> (with-current-buffer (get-buffer-create bufrn)
> 
> (org-mode) (princ obj))
> 
> (pop-to-buffer bufrn))

I have this function:

(defun rcd-pop-to-report (string &optional buffer-name map place refresh 
truncate return-function)
  "Pop the new buffer and inserts STRING.
Quits with `q' if necessary.
BUFFER-NAME is optional.

It will destroy the buffer before display of report."
  (let ((buffer (or buffer-name "*RCD Report*")))
    (when (buffer-live-p (get-buffer buffer))
      (kill-buffer (get-buffer buffer)))
    (save-excursion
      (pop-to-buffer buffer)
      (let ((word-wrap truncate))
        (when word-wrap (toggle-truncate-lines 1))
        (setq rcd-db-current-table (when (listp place) (cdr (assoc "table" 
place))))
        (setq rcd-db-current-column (when (listp place) (cdr (assoc "column" 
place))))
        (setq rcd-db-current-table-id (when (listp place) (cdr (assoc 
"table-id" place))))
        (setq rcd-tabulated-refresh-function refresh)
        (setq rcd-current-return-function return-function)
        (insert string)
        (goto-char 1)
        (cond (map (use-local-map map))
              (t (local-set-key (kbd "q") 'kill-buffer-and-window)))
        (read-only-mode 1)))))

Then maybe I can shorten it:

(defun rcd-pop-to-report (string &optional buffer-name mode)
  "Pop the new buffer and inserts STRING.
BUFFER-NAME is optional.
MODE is optional, shall be symbol of the mode.

Funcation will destroy the buffer before display of report."
  (let ((buffer (or buffer-name "*RCD Report*")))
    (when (buffer-live-p (get-buffer buffer))
      (kill-buffer (get-buffer buffer)))
    (save-excursion
      (pop-to-buffer buffer)
        (insert string)
        (goto-char 1)
        (cond (mode (funcall mode))
              (t (read-only-mode 1))))))

(rcd-pop-to-report "** Hello there" nil 'org-mode)


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]