emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Add `notes' function to store random notes across Emacs rest


From: Michal Nazarewicz
Subject: Re: [PATCH] Add `notes' function to store random notes across Emacs restarts.
Date: Mon, 17 Jun 2013 22:39:40 +0200
User-agent: Notmuch/0.15.2+55~geb6e9d8 (http://notmuchmail.org) Emacs/24.3.50.1 (x86_64-unknown-linux-gnu)

On Mon, Jun 17 2013, Juanma Barranquero wrote:
>> +only one C-c C-c binding which saves and buries the buffer.
>
> Use \\[notes-save-and-bury] instead of hard-coded C-c C-c

I'm not certain how that's supposed to work.  The binding is not in
global key map after all.

>> +      ;; We don't want a "Buffer modified" prompt from kill-buffer so
>> +      ;; we have to use advice rather than a hook.
>> +      (advice-add 'kill-buffer :around 'notes--kill-buffer-advice)
>
> Why cannot  that be done from kill-buffer-hook?

Because kill-buffer-hook is called after kill-buffer checks whether file
is modified:

DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 0, 1, "bKill buffer: ",
       doc: /* … */)
  (Lisp_Object buffer_or_name)
/* … */

  /* Query if the buffer is still modified.  */
  if (INTERACTIVE && !NILP (BVAR (b, filename))
      && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
    {
      GCPRO1 (buffer);
      tem = do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ",
                                     BVAR (b, name), make_number (0)));
      UNGCPRO;
      if (NILP (tem))
        return Qnil;
    }

  /* Run hooks with the buffer to be killed the current buffer.  */
  {
    ptrdiff_t count = SPECPDL_INDEX ();
    Lisp_Object arglist[1];

    record_unwind_protect (save_excursion_restore, save_excursion_save ());
    set_buffer_internal (b);

    /* First run the query functions; if any query is answered no,
       don't kill the buffer.  */
    arglist[0] = Qkill_buffer_query_functions;
    tem = Frun_hook_with_args_until_failure (1, arglist);
    if (NILP (tem))
      return unbind_to (count, Qnil);

    /* Then run the hooks.  */
    Frun_hooks (1, &Qkill_buffer_hook);
    unbind_to (count, Qnil);
  }
/* … */
}

I'll add some more explanation to the comment but other than that, short
of creating a new hook, I see no other satisfactory solution.


(All other comments applied to the code).

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: address@hidden>--------------ooO--(_)--Ooo--

Attachment: signature.asc
Description: PGP signature


reply via email to

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