Subject: 26.1; Behavior of buffer-offer-save not lining up with documentation

From: Brad Lindsay <[email-masked]>
Date: Thu, 28 Jun 2018 15:56:59 -0700

I am trying to create a function that creates a new empty buffer that
prompts you to save it when you kill it. Reading through the
documentation, it looks like I need to set “buffer-offer-save” to a
non-nil value since the new buffer is not a file-visiting buffer. I
have tried doing that, and verifying that the variable isn’t set and
that the new buffer isn’t empty, but when I close (kill) the buffer, I
don’t get a prompt.

Here is my function definition:

(defun buffer-new ()
  "Creates a new Untitled buffer with the same modes as the current one."
  (interactive)
  (let
      ((new-buffer (generate-new-buffer "Untitled"))
       (mode major-mode))
    (switch-to-buffer new-buffer)
    (funcall mode)
    (setq buffer-offer-save t)
    new-buffer)
  )

In GNU Emacs 26.1 (build 1, x86_64-apple-darwin14.5.0, NS
appkit-1348.17 Version 10.10.5 (Build 14F2511))
 of 2018-05-30 built on builder10-10.porkrind.org
Windowing system distributor 'Apple', version 10.3.1641
Recent messages:
Wrote /Users/bladmin/.emacs.d/init/editor.el
C-c C-g is undefined
Importing package-keyring.gpg...done
Package refresh done
C-c h is undefined
Type C-x 1 to delete the help window.
Mark set [2 times]
Saving file /Users/bladmin/.emacs.d/init/editor.el...
Wrote /Users/bladmin/.emacs.d/init/editor.el
Quit

Configured using:
 'configure --with-ns '--enable-locallisppath=/Library/Application
 Support/Emacs/${version}/site-lisp:/Library/Application
 Support/Emacs/site-lisp' --with-modules'

Configured features:
NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES THREADS

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Emacs-Lisp

Minor modes in effect:
  diff-auto-refine-mode: t
  subword-mode: t
  display-line-numbers-mode: t
  company-flx-mode: t
  company-mode: t
  desktop-save-mode: t
  yas-minor-mode: t
  global-origami-mode: t
  origami-mode: t
  projectile-mode: t
  ido-vertical-mode: t
  flx-ido-mode: t
  ido-everywhere: t
  xterm-mouse-mode: t
  delete-selection-mode: t
  electric-pair-mode: t
  show-paren-mode: t
  global-auto-revert-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug sendmail pp cl-print help-fns radix-tree
mm-archive message dired dired-loaddefs format-spec rfc822 mml mml-sec
epa derived gnus-util rmail rmail-loaddefs mailabbrev gmm-utils
mailheader mm-decode mm-bodies mm-encode mail-utils network-stream
starttls url-cache epg rspec-mode robe inf-ruby ruby-mode vc-git
diff-mode company-oddmuse company-keywords company-etags company-gtags
company-files company-capf company-cmake company-xcode company-clang
company-semantic company-eclim company-template company-bbdb
company-robe cap-words superword subword display-line-numbers
exec-path-from-shell web-mode disp-table pug-mode alchemist
alchemist-macroexpand alchemist-company alchemist-help
alchemist-complete company-dabbrev-code company-dabbrev
alchemist-refcard alchemist-phoenix alchemist-compile alchemist-iex
alchemist-message easy-mmode alchemist-hooks alchemist-hex alchemist-mix
alchemist-info alchemist-goto alchemist-scope etags xref project
alchemist-eval alchemist-interact alchemist-server alchemist-execute
alchemist-report alchemist-test-mode alchemist-project alchemist-file
alchemist-key alchemist-utils elixir-mode elixir-format pkg-info
url-http tls gnutls url-auth mail-parse rfc2231 rfc2047 rfc2045 mm-util
ietf-drums mail-prsvr url-gw nsm rmc puny find-func lisp-mnt epl
elixir-smie company-flx company pcase elm-mode elm-interactive url
url-proxy url-privacy url-expand url-methods url-history url-cookie
url-domsuf url-util mailcap subr-x elm-font-lock elm-indent elm-imenu
imenu elm-format elm-tags elm-util let-alist json map f dockerfile-mode
sh-script smie executable yaml-mode chruby desktop frameset cus-start
cus-load yasnippet key-chord cl-extra help-mode hydra lv neotree origami
origami-parsers rx cl s dash projectile grep compile comint ansi-color
ring ibuf-ext ibuffer ibuffer-loaddefs thingatpt ido-vertical-mode
flx-ido advice flx ido material_darker-theme xt-mouse delsel elec-pair
paren autorevert filenotify edmacro kmacro finder-inf info package
easymenu epg-config url-handlers url-parse auth-source cl-seq eieio
eieio-core cl-macs eieio-loaddefs password-cache url-vars seq byte-opt
gv bytecomp byte-compile cconv cl-loaddefs cl-lib time-date tooltip
eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
term/ns-win ns-win ucs-normalize mule-util term/common-win tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page menu-bar
rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core term/tty-colors frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote kqueue cocoa ns
multi-tty make-network-process emacs)

Memory information:
((conses 16 478806 471794)
 (symbols 48 37892 10)
 (miscs 40 1233 376)
 (strings 32 113275 66990)
 (string-bytes 1 4372073)
 (vectors 16 68500)
 (vector-slots 8 1933976 243756)
 (floats 8 104 570)
 (intervals 56 996 636)
 (buffers 992 18))