0

I have the following function to produce a form that can be "printed" to a ~/.gnus file to configure gnus to use a certain stmp and imap server for an account:

(defun gnus-imap-smtp-form (email smtp-server-port imap-server-port)
  (destructuring-bind ((smtp-server . smtp-port) . (imap-server . imap-port))
      (cons smtp-server-port imap-server-port)
    `(let ((email ,email)
       (smtp-server ,smtp-server)
       (smtp-port ,smtp-port)
       (imap-server ,imap-server)
       (imap-port ,imap-port))
       (setf gnus-select-method
         `(nnimap ,email
              (nnimap-address ,imap-server)
              (nnimap-server-port ,imap-port)
              (nnimap-stream ssl)))

       (setf message-send-mail-function 'smtpmail-send-it
         smtpmail-starttls-credentials `((,smtp-server ,smtp-port nil nil))
         smtpmail-auth-credentials `((,smtp-server ,smtp-port
                               ,email nil))
         smtpmail-default-smtp-server smtp-server
         smtpmail-smtp-server smtp-server
         smtpmail-smtp-service smtp-port
         gnus-ignored-newsgroups
         "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")

       (setf user-mail-address email)
       (setf smtpmail-stream-type 'starttls))))

In the past, the above has generated the correct form:

(gnus-imap-smtp-form "me@company.com" '("my.company.smtp" . 587) '("my.company.imap" . 993))


(let
       ((email "me@company.com")
        (smtp-server "my.company.smtp")
        (smtp-port 25)
        (imap-server "my.company.imap")
        (imap-port 993))
     (setf gnus-select-method
           `(nnimap ,email
            (nnimap-address ,imap-server)
            (nnimap-server-port ,imap-port)
            (nnimap-stream ssl)))
     (setf message-send-mail-function 'smtpmail-send-it smtpmail-starttls-credentials
           `((,smtp-server ,smtp-port nil nil))
           smtpmail-auth-credentials
           `((,smtp-server ,smtp-port ,email nil))
           smtpmail-default-smtp-server smtp-server smtpmail-smtp-server smtp-server smtpmail-smtp-service smtp-port gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
     (setf user-mail-address email)
     (setf smtpmail-stream-type 'starttls))

Today, I tried to generate the form for another account, but I am getting triple dots ... instead of nested backquotes:

(gnus-imap-smtp-form "me@gmail.com" '("smtp.gmail.com" . 587) '("imap.gmail.com" . 993)) 


    (let
    ((email "me@gmail.com")
     (smtp-server "smtp.gmail.com")
     (smtp-port 587)
     (imap-server "imap.gmail.com")
     (imap-port 993))
  (setf gnus-select-method
    `(nnimap ... ... ... ...))
  (setf message-send-mail-function 'smtpmail-send-it smtpmail-starttls-credentials
    `(...)
    smtpmail-auth-credentials
    `(...)
    smtpmail-default-smtp-server smtp-server smtpmail-smtp-server smtp-server smtpmail-smtp-service ...)
  (setf user-mail-address email)
  (setf smtpmail-stream-type 'starttls))

What could be happening?

I've tried (prin1 form), let-binding to nil both eval-expression-print-length and eval-expression-print-level, but prin1 still abbreviates the expression:

(let ((eval-expression-print-length nil)
      (eval-expression-print-level nil))
      (prin1 form))
(let ((email "me@gmail.com") (smtp-server "smtp.gmail.com") (smtp-port 587) (imap-server "imap.gmail.com") (imap-port 993)) (setf gnus-select-method (\` (nnimap ... ... ... ...))) (setf message-send-mail-function (quote smtpmail-send-it) smtpmail-starttls-credentials (\` (...)) smtpmail-auth-credentials (\` (...)) smtpmail-default-smtp-server smtp-server smtpmail-smtp-server smtp-server smtpmail-smtp-service ...) (setf user-mail-address email) (setf smtpmail-stream-type (quote starttls)))
(let
    ((email "me@gmail.com")
     (smtp-server "smtp.gmail.com")
     (smtp-port 587)
     (imap-server "imap.gmail.com")
     (imap-port 993))
  (setf gnus-select-method
    `(nnimap ... ... ... ...))
  (setf message-send-mail-function 'smtpmail-send-it smtpmail-starttls-credentials
    `(...)
    smtpmail-auth-credentials
    `(...)
    smtpmail-default-smtp-server smtp-server smtpmail-smtp-server smtp-server smtpmail-smtp-service ...)
  (setf user-mail-address email)
  (setf smtpmail-stream-type 'starttls))

Binding print-level and print-length:

(let ((eval-expression-print-length nil)
         (eval-expression-print-level nil)
         (print-level nil)
         (print-length nil))
     (prin1 form))
(let ((email "me@gmail.com") (smtp-server "smtp.gmail.com") (smtp-port 587) (imap-server "imap.gmail.com") (imap-port 993)) (setf gnus-select-method (\` (nnimap (\, email) (nnimap-address (\, imap-server)) (nnimap-server-port (\, imap-port)) (nnimap-stream ssl)))) (setf message-send-mail-function (quote smtpmail-send-it) smtpmail-starttls-credentials (\` (((\, smtp-server) (\, smtp-port) nil nil))) smtpmail-auth-credentials (\` (((\, smtp-server) (\, smtp-port) (\, email) nil))) smtpmail-default-smtp-server smtp-server smtpmail-smtp-server smtp-server smtpmail-smtp-service smtp-port gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]") (setf user-mail-address email) (setf smtpmail-stream-type (quote starttls)))
(let
    ((email "me@gmail.com")
     (smtp-server "smtp.gmail.com")
     (smtp-port 587)
     (imap-server "imap.gmail.com")
     (imap-port 993))
  (setf gnus-select-method
    `(nnimap ... ... ... ...))
  (setf message-send-mail-function 'smtpmail-send-it smtpmail-starttls-credentials
    `(...)
    smtpmail-auth-credentials
    `(...)
    smtpmail-default-smtp-server smtp-server smtpmail-smtp-server smtp-server smtpmail-smtp-service ...)
  (setf user-mail-address email)
  (setf smtpmail-stream-type 'starttls))
erjoalgo
  • 853
  • 1
  • 5
  • 18
  • Seems like an issue with [`eval-expression-print-level`](https://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Eval.html). Try setting it to `nil`; do you still get the same result? – Tianxiang Xiong Apr 11 '17 at 17:35
  • I bound the form to a variable and inspected it with accessors in elisp: I can see the expected form values, which makes sense. But I've tried let-binding both `eval-expression-print-level` and `eval-expression-print-length` to nil, but I'm still getting the dots on `(pp form)` – erjoalgo Apr 11 '17 at 18:10
  • I've gone down all the way to `(prin1 form)`, which is in C source, but `(prin1 form)` still produces the dots – erjoalgo Apr 11 '17 at 18:12
  • OK, `pp` uses `prin1`, so try binding `print-level` instead of `eval-expression-print-level`. – Tianxiang Xiong Apr 11 '17 at 18:59
  • I've tried print-level, still getting the abbreviations, added my edit above – erjoalgo Apr 11 '17 at 19:06
  • 1
    How are you printing the form? By `eval-expression` and seeing the results in the echo area? That's controlled by the `eval-expression-` vars. For general printing, `print-` vars are used directly. See [related question](http://emacs.stackexchange.com/questions/27338/lisp-form-print-depth). – Tianxiang Xiong Apr 11 '17 at 19:18
  • What version of Emacs are you using? I'm actually seeing the same with a simple form like `(macroexpand '(defun foo () (let ((bar)) (+ 1 2))))` on Emacs 25.1. – Tianxiang Xiong Apr 11 '17 at 19:24
  • `GNU Emacs 24.4.1 (x86_64-pc-linux-gnu, GTK+ Version 3.14.5) of 2015-03-07 on trouble, modified by Debian`. are you seeing the same (bad) behavior? – erjoalgo Apr 11 '17 at 20:32
  • I'm printing the form by `pp`, which uses `prin1` – erjoalgo Apr 11 '17 at 23:48
  • @TianxiangXiong since you originally pointed out the `eval-expression-print-level`, I'd be happy to accept your answer if you could also address why the `let` binding didn't work – erjoalgo Apr 13 '17 at 17:28

1 Answers1

1

Using setf instead of a let binding to set the value of print-level and print-depth worked, though I'm not sure I understand why:

(progn (setf print-level 2
            print-length 2)
          (pp `(deeply (nested (form (very (deeply (nested))))))))
(deeply
 (nested ...))

"(deeply\n (nested ...))\n"

Setting to nil:

(progn (setf print-level nil
            print-length nil)
          (pp `(deeply (nested (form (very (deeply (nested))))))))
(deeply
 (nested
  (form
   (very
    (deeply
     (nested))))))

"(deeply\n (nested\n  (form\n   (very\n    (deeply\n     (nested))))))\n"
erjoalgo
  • 853
  • 1
  • 5
  • 18