Add `remember-notes' function to store random notes across Emacs
restarts. * remember.el (remember-data-file): Add :set callback to affect notes buffer (if any). (remember-notes): New command. (remember-notes-buffer-name, bury-remember-notes-on-kill): New defcustoms for the `remember-notes' function. (remember-notes-save-and-bury-buffer): New command. (remember-notes-mode-map): New variable. (remember-mode): New minor mode. (remember-notes--kill-buffer-query): New function. * lisp/startup.el (initial-buffer-choice): Add notes to custom type. * src/buffer.c (FKill_buffer): Run `kill-buffer-query-functions' before checking whether buffer is modified. This lets `kill-buffer-query-functions' cancel killing of the buffer or save its content before `kill-buffer' asks user the "Buffer %s modified; kill anyway?" question. * remember.el (remember-append-to-file): Don't mix `find-buffer-visiting' and `get-file-buffer'. * lisp/files.el (find-file-noselect): Simplify conditional expression.
This commit is contained in:
parent
6d89e343ab
commit
ef099a941f
9 changed files with 207 additions and 49 deletions
|
@ -1065,7 +1065,7 @@ Buffer foo.changed modified; kill anyway? (yes or no) @kbd{yes}
|
|||
@end deffn
|
||||
|
||||
@defvar kill-buffer-query-functions
|
||||
After confirming unsaved changes, @code{kill-buffer} calls the functions
|
||||
Before confirming unsaved changes, @code{kill-buffer} calls the functions
|
||||
in the list @code{kill-buffer-query-functions}, in order of appearance,
|
||||
with no arguments. The buffer being killed is the current buffer when
|
||||
they are called. The idea of this feature is that these functions will
|
||||
|
|
8
etc/NEWS
8
etc/NEWS
|
@ -90,6 +90,14 @@ simply disabling Transient Mark mode does the same thing.
|
|||
** `initial-buffer-choice' can now specify a function to set up the
|
||||
initial buffer.
|
||||
|
||||
** `remember-notes' creates a buffer whose content is saved on kill-emacs.
|
||||
You may think of it as a *scratch* buffer whose content is preserved.
|
||||
In fact, it was designed as a replacement for *scratch* buffer and can
|
||||
be used that way by setting `initial-buffer-choice' to `remember-notes'
|
||||
and `remember-notes-buffer-name' to "*scratch*". Without the second
|
||||
change, *scratch* buffer will still be there for notes that do not
|
||||
need to be preserved.
|
||||
|
||||
** `write-region-inhibit-fsync' now defaults to t in batch mode.
|
||||
|
||||
** ACL support has been added.
|
||||
|
|
|
@ -1,18 +1,37 @@
|
|||
2013-06-30 Michal Nazarewicz <mina86@mina86.com>
|
||||
|
||||
* files.el (find-file-noselect): Simplify conditional expression.
|
||||
|
||||
* remember.el (remember-append-to-file):
|
||||
Don't mix `find-buffer-visiting' and `get-file-buffer'.
|
||||
|
||||
Add `remember-notes' function to store random notes across Emacs
|
||||
restarts.
|
||||
* remember.el (remember-data-file): Add :set callback to affect
|
||||
notes buffer (if any).
|
||||
(remember-notes): New command.
|
||||
(remember-notes-buffer-name, bury-remember-notes-on-kill):
|
||||
New defcustoms for the `remember-notes' function.
|
||||
(remember-notes-save-and-bury-buffer): New command.
|
||||
(remember-notes-mode-map): New variable.
|
||||
(remember-mode): New minor mode.
|
||||
(remember-notes--kill-buffer-query): New function.
|
||||
* startup.el (initial-buffer-choice): Add notes to custom type.
|
||||
|
||||
2013-06-30 Eli Zaretskii <eliz@gnu.org>
|
||||
|
||||
* bindings.el (right-char, left-char): Don't call sit-for, this is
|
||||
no longer needed. Use arithmetic comparison only for numerical
|
||||
arguments.
|
||||
|
||||
* international/mule-cmds.el (select-safe-coding-system): Handle
|
||||
the case of FROM being a string correctly. (Bug#14755)
|
||||
* international/mule-cmds.el (select-safe-coding-system):
|
||||
Handle the case of FROM being a string correctly. (Bug#14755)
|
||||
|
||||
2013-06-30 Lars Magne Ingebrigtsen <larsi@gnus.org>
|
||||
|
||||
* net/shr.el (shr-make-table-1): Add a sanity check that allows
|
||||
progression on degenerate tables.
|
||||
(shr-rescale-image): ImageMagick animated images currently doesn't
|
||||
work.
|
||||
(shr-rescale-image): ImageMagick animated images currently don't work.
|
||||
|
||||
2013-06-30 Juanma Barranquero <lekktu@gmail.com>
|
||||
|
||||
|
@ -28,8 +47,8 @@
|
|||
|
||||
2013-06-30 Dmitry Gutov <dgutov@yandex.ru>
|
||||
|
||||
* progmodes/ruby-mode.el (ruby-syntax-propertize-function): Don't
|
||||
start heredoc inside a string or comment.
|
||||
* progmodes/ruby-mode.el (ruby-syntax-propertize-function):
|
||||
Don't start heredoc inside a string or comment.
|
||||
|
||||
2013-06-29 Eli Zaretskii <eliz@gnu.org>
|
||||
|
||||
|
@ -80,7 +99,7 @@
|
|||
|
||||
2013-06-27 Lars Magne Ingebrigtsen <larsi@gnus.org>
|
||||
|
||||
* net/shr.el (add-face-text-property): Removed compat definition.
|
||||
* net/shr.el (add-face-text-property): Remove compat definition.
|
||||
|
||||
2013-06-27 Stephen Berman <stephen.berman@gmx.net>
|
||||
|
||||
|
|
|
@ -1859,13 +1859,12 @@ the various files."
|
|||
(setq buffer-read-only read-only)))
|
||||
(setq buffer-file-read-only read-only))
|
||||
|
||||
(when (and (not (eq (not (null rawfile))
|
||||
(not (null find-file-literally))))
|
||||
(not nonexistent)
|
||||
;; It is confusing to ask whether to visit
|
||||
;; non-literally if they have the file in
|
||||
;; hexl-mode or image-mode.
|
||||
(not (memq major-mode '(hexl-mode image-mode))))
|
||||
(unless (or (eq (null rawfile) (null find-file-literally))
|
||||
nonexistent
|
||||
;; It is confusing to ask whether to visit
|
||||
;; non-literally if they have the file in
|
||||
;; hexl-mode or image-mode.
|
||||
(memq major-mode '(hexl-mode image-mode)))
|
||||
(if (buffer-modified-p)
|
||||
(if (y-or-n-p
|
||||
(format
|
||||
|
|
|
@ -53,7 +53,8 @@ or directory when no target file is specified."
|
|||
(const :tag "Startup screen" nil)
|
||||
(directory :tag "Directory" :value "~/")
|
||||
(file :tag "File" :value "~/.emacs")
|
||||
(function :tag "Function")
|
||||
(const :tag "Notes buffer" remember-notes)
|
||||
(function :tag "Function")
|
||||
(const :tag "Lisp scratch buffer" t))
|
||||
:version "24.4"
|
||||
:group 'initialization)
|
||||
|
|
|
@ -382,8 +382,18 @@ Subject: %s\n\n"
|
|||
;; Remembering to plain files
|
||||
|
||||
(defcustom remember-data-file (locate-user-emacs-file "notes" ".notes")
|
||||
"The file in which to store unprocessed data."
|
||||
"The file in which to store unprocessed data.
|
||||
When set via customize, visited file of the notes buffer (if it
|
||||
exists) might be changed."
|
||||
:type 'file
|
||||
:set (lambda (symbol value)
|
||||
(let ((buf (find-buffer-visiting (default-value symbol))))
|
||||
(set-default symbol value)
|
||||
(when (buffer-live-p buf)
|
||||
(with-current-buffer buf
|
||||
(set-visited-file-name
|
||||
(expand-file-name remember-data-file))))))
|
||||
:initialize 'custom-initialize-default
|
||||
:group 'remember)
|
||||
|
||||
(defcustom remember-leader-text "** "
|
||||
|
@ -393,21 +403,20 @@ Subject: %s\n\n"
|
|||
|
||||
(defun remember-append-to-file ()
|
||||
"Remember, with description DESC, the given TEXT."
|
||||
(let ((text (buffer-string))
|
||||
(desc (remember-buffer-desc)))
|
||||
(with-temp-buffer
|
||||
(insert "\n" remember-leader-text (current-time-string)
|
||||
" (" desc ")\n\n" text)
|
||||
(if (not (bolp))
|
||||
(insert "\n"))
|
||||
(if (find-buffer-visiting remember-data-file)
|
||||
(let ((remember-text (buffer-string)))
|
||||
(set-buffer (get-file-buffer remember-data-file))
|
||||
(save-excursion
|
||||
(goto-char (point-max))
|
||||
(insert remember-text)
|
||||
(when remember-save-after-remembering (save-buffer))))
|
||||
(append-to-file (point-min) (point-max) remember-data-file)))))
|
||||
(let* ((text (buffer-string))
|
||||
(desc (remember-buffer-desc))
|
||||
(remember-text (concat "\n" remember-leader-text (current-time-string)
|
||||
" (" desc ")\n\n" text
|
||||
(save-excursion (goto-char (point-max))
|
||||
(if (bolp) nil "\n"))))
|
||||
(buf (find-buffer-visiting remember-data-file)))
|
||||
(if buf
|
||||
(with-current-buffer buf
|
||||
(save-excursion
|
||||
(goto-char (point-max))
|
||||
(insert remember-text))
|
||||
(if remember-save-after-remembering (save-buffer)))
|
||||
(append-to-file remember-text nil remember-data-file))))
|
||||
|
||||
(defun remember-region (&optional beg end)
|
||||
"Remember the data from BEG to END.
|
||||
|
@ -551,4 +560,96 @@ the data away for latter retrieval, and possible indexing.
|
|||
\\{remember-mode-map}"
|
||||
(set-keymap-parent remember-mode-map nil))
|
||||
|
||||
;; Notes buffer showing the notes:
|
||||
|
||||
(defcustom remember-notes-buffer-name "*notes*"
|
||||
"Name of the notes buffer.
|
||||
Setting it to *scratch* will hijack the *scratch* buffer for the
|
||||
purpose of storing notes."
|
||||
:type 'string
|
||||
:version "24.4")
|
||||
|
||||
(defcustom remember-notes-initial-major-mode nil
|
||||
"Major mode to set to notes buffer when it's created.
|
||||
If set to nil will use the same mode as `initial-major-mode'."
|
||||
:type '(choice (const :tag "Same as `initial-major-mode'" nil)
|
||||
(function :tag "Major mode" text-mode))
|
||||
:version "24.4")
|
||||
|
||||
(defcustom remember-notes-bury-on-kill t
|
||||
"Whether to bury notes buffer instead of killing."
|
||||
:type 'boolean
|
||||
:version "24.4")
|
||||
|
||||
(defun remember-notes-save-and-bury-buffer ()
|
||||
"Saves and buries current buffer.
|
||||
Buffer is saved only if `buffer-modified-p' returns non-nil."
|
||||
(interactive)
|
||||
(when (buffer-modified-p)
|
||||
(save-buffer))
|
||||
(bury-buffer))
|
||||
|
||||
|
||||
|
||||
(defvar remember-notes-mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(define-key map "\C-c\C-c" 'remember-notes-save-and-bury-buffer)
|
||||
map)
|
||||
"Keymap used in remember-notes mode.")
|
||||
|
||||
(define-minor-mode remember-notes-mode
|
||||
"Minor mode for the `remember-notes' buffer."
|
||||
nil nil nil
|
||||
(cond
|
||||
(remember-notes-mode
|
||||
(add-hook 'kill-buffer-query-functions
|
||||
#'remember-notes--kill-buffer-query nil t)
|
||||
(setq buffer-save-without-query t))))
|
||||
|
||||
;;;###autoload
|
||||
(defun remember-notes (&optional switch-to)
|
||||
"Creates notes buffer and switches to it if called interactively.
|
||||
|
||||
If a notes buffer created by a previous invocation of this
|
||||
function already exist, it will be returned. Otherwise a new
|
||||
buffer will be created whose content will be read from file
|
||||
pointed by `remember-data-file'. If a buffer visiting this file
|
||||
already exist, that buffer will be used instead of creating a new
|
||||
one (see `find-file-noselect' function for more details).
|
||||
|
||||
Name of the created buffer is taken from `remember-notes-buffer-name'
|
||||
variable and if a buffer with that name already exist (but was not
|
||||
created by this function), it will be first killed.
|
||||
\\<remember-notes-mode-map>
|
||||
`remember-notes-mode' is active in the notes buffer which by default
|
||||
contains only one \\[save-and-bury-buffer] binding which saves and
|
||||
buries the buffer.
|
||||
|
||||
Function returns notes buffer. When called interactively,
|
||||
switches to it as well.
|
||||
|
||||
Notes buffer is meant for keeping random notes which you'd like to
|
||||
preserve across Emacs restarts. The notes will be stored in the
|
||||
`remember-data-file'."
|
||||
(interactive "p")
|
||||
(let ((buf (or (find-buffer-visiting remember-data-file)
|
||||
(with-current-buffer (find-file-noselect remember-data-file)
|
||||
(and remember-notes-buffer-name
|
||||
(not (get-buffer remember-notes-buffer-name))
|
||||
(rename-buffer remember-notes-buffer-name))
|
||||
(funcall (or remember-notes-initial-major-mode
|
||||
initial-major-mode))
|
||||
(remember-notes-mode 1)
|
||||
(current-buffer)))))
|
||||
(when switch-to
|
||||
(switch-to-buffer buf))
|
||||
buf))
|
||||
|
||||
(defun remember-notes--kill-buffer-query ()
|
||||
(when (buffer-modified-p)
|
||||
(save-buffer))
|
||||
(if remember-notes-bury-on-kill
|
||||
(bury-buffer)
|
||||
t))
|
||||
|
||||
;;; remember.el ends here
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
2013-06-30 Michal Nazarewicz <mina86@mina86.com>
|
||||
|
||||
* buffer.c (FKill_buffer): Run `kill-buffer-query-functions'
|
||||
before checking whether buffer is modified. This lets
|
||||
`kill-buffer-query-functions' cancel killing of the buffer or save
|
||||
its content before `kill-buffer' asks user the "Buffer %s
|
||||
modified; kill anyway?" question.
|
||||
|
||||
2013-06-30 Jan Djärv <jan.h.d@swipnet.se>
|
||||
|
||||
* nsfns.m (handlePanelKeys): Don't process Command+Function keys.
|
||||
|
@ -59,6 +67,24 @@
|
|||
:prefer-utf-8.
|
||||
(syms_of_coding): Adjust for coding_arg_undecided_max.
|
||||
|
||||
2013-06-28 Kenichi Handa <handa@gnu.org>
|
||||
|
||||
* coding.h (define_coding_undecided_arg_index): New enum.
|
||||
(coding_attr_index): New members
|
||||
coding_attr_undecided_inhibit_null_byte_detection,
|
||||
coding_attr_undecided_inhibit_iso_escape_detection,
|
||||
coding_attr_undecided_prefer_utf_8.
|
||||
(undecided_spec): New struct.
|
||||
(struct coding_system): New member `undecided' of the member `spec'.
|
||||
|
||||
* coding.c (setup_coding_system): Handle CODING->spec.undecided.
|
||||
(detect_coding): Likewise.
|
||||
(detect_coding_system): Likewise.
|
||||
(Fdefine_coding_system_internal): New coding system properties
|
||||
:inhibit-null-byte-detection, :inhibit-iso-escape-detection, and
|
||||
:prefer-utf-8.
|
||||
(syms_of_coding): Adjust for coding_arg_undecided_max.
|
||||
|
||||
2013-06-28 Paul Eggert <eggert@cs.ucla.edu>
|
||||
|
||||
* image.c (x_from_xcolors): Remove unused local.
|
||||
|
@ -75,8 +101,8 @@
|
|||
(x_clear_image_1): New arg `flags' instead of 3 bools `pixmap_p',
|
||||
`mask_p', and `colors_p'. All uses changed.
|
||||
(x_clear_image_1) [HAVE_X_WINDOWS]: Destroy `ximg' and `mask_img'.
|
||||
(CLEAR_IMAGE_PIXMAP, CLEAR_IMAGE_MASK, CLEAR_IMAGE_COLORS): New
|
||||
macros for `flags' arg to x_clear_image_1.
|
||||
(CLEAR_IMAGE_PIXMAP, CLEAR_IMAGE_MASK, CLEAR_IMAGE_COLORS):
|
||||
New macros for `flags' arg to x_clear_image_1.
|
||||
(postprocess_image, xpm_load_image, x_build_heuristic_mask)
|
||||
(png_load_body): Use x_clear_image_1 instead of Free_Pixmap.
|
||||
(ZPixmap, XGetImage) [HAVE_NS]: Remove.
|
||||
|
@ -343,7 +369,7 @@
|
|||
* textprop.c (property_set_type): New enum.
|
||||
(add_properties): Allow appending/prepending text properties.
|
||||
(add_text_properties_1): Factored out of Fadd_text_properties.
|
||||
(Fadd_text_properties): Moved all the code into
|
||||
(Fadd_text_properties): Move all the code into
|
||||
add_text_properties_1.
|
||||
(Fadd_face_text_property): New function that calls
|
||||
add_text_properties_1.
|
||||
|
@ -914,7 +940,7 @@
|
|||
(Fxw_color_values): Use EmacsCGFloat
|
||||
(Fns_display_monitor_attributes_list): Only get screen number for
|
||||
Cocoa.
|
||||
(getDirectory, getFilename): Removed from EmacsOpenPanel and
|
||||
(getDirectory, getFilename): Remove from EmacsOpenPanel and
|
||||
EmacsSavePanel.
|
||||
(EmacsOpenPanel:ok:): Use ns_filename_from_panel and
|
||||
ns_directory_from_panel.
|
||||
|
|
28
src/buffer.c
28
src/buffer.c
|
@ -1734,18 +1734,6 @@ cleaning up all windows currently displaying the buffer to be killed. */)
|
|||
if (!BUFFER_LIVE_P (b))
|
||||
return Qnil;
|
||||
|
||||
/* 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 ();
|
||||
|
@ -1761,6 +1749,22 @@ cleaning up all windows currently displaying the buffer to be killed. */)
|
|||
if (NILP (tem))
|
||||
return unbind_to (count, Qnil);
|
||||
|
||||
/* 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 unbind_to (count, Qnil);
|
||||
}
|
||||
|
||||
/* If the hooks have killed the buffer, exit now. */
|
||||
if (!BUFFER_LIVE_P (b))
|
||||
return unbind_to (count, Qt);
|
||||
|
||||
/* Then run the hooks. */
|
||||
Frun_hooks (1, &Qkill_buffer_hook);
|
||||
unbind_to (count, Qnil);
|
||||
|
|
|
@ -20110,7 +20110,7 @@ Value is the new character position of point. */)
|
|||
w->cursor.vpos = -1;
|
||||
return make_number (PT);
|
||||
}
|
||||
else if (!INTEGERP (g->object) && g->object != gpt->object)
|
||||
else if (!INTEGERP (g->object) && !EQ (g->object, gpt->object))
|
||||
{
|
||||
ptrdiff_t new_pos;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue