From: Daniel Colascione <dan.colascione@gmail.com>
To: Emacs development discussions <emacs-devel@gnu.org>
Subject: [PATCH] auto-EOF for bookmarks
Date: Sun, 10 Jul 2011 19:05:22 -0700 [thread overview]
Message-ID: <4E1A5A62.3050906@gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 337 bytes --]
This patch changes the bookmark feature to automatically jump to the end
of the buffer if a bookmark was set there. It is backwards-compatible.
If the change in default behavior is too drastic, then would it be okay
to add a facility to explicitly set a follow-EOF bookmark?
(Not planning to merge for feature freeze, of course.)
[-- Attachment #1.2: at-eof.patch --]
[-- Type: text/plain, Size: 3323 bytes --]
=== modified file 'lisp/bookmark.el'
--- lisp/bookmark.el 2011-07-05 15:31:22 +0000
+++ lisp/bookmark.el 2011-07-11 02:02:05 +0000
@@ -381,10 +381,18 @@
(bookmark-prop-get bookmark-name-or-record 'position))
+(defun bookmark-get-at-eof (bookmark-name-or-record)
+ "Return the at-eof flag of BOOKMARK-NAME-OR-RECORD, or nil if none."
+ (bookmark-prop-get bookmark-name-or-record 'at-eof))
+
+
(defun bookmark-set-position (bookmark-name-or-record position)
"Set the position (i.e.: point) of BOOKMARK-NAME-OR-RECORD to POSITION."
(bookmark-prop-set bookmark-name-or-record 'position position))
+(defun bookmark-set-at-eof (bookmark-name-or-record at-eof-flag)
+ "Set the at-eof flag of BOOKMARK-NAME-OR-RECORD to AT-EOF_FLAG."
+ (bookmark-prop-set bookmark-name-or-record 'at-eof at-eof-flag))
(defun bookmark-get-front-context-string (bookmark-name-or-record)
"Return the front-context-string of BOOKMARK-NAME-OR-RECORD, or nil if none."
@@ -544,6 +552,12 @@
(point)
(- (point) bookmark-search-size))
nil))))
+ ,@(when (save-excursion
+ (save-restriction
+ (widen)
+ (when posn (goto-char posn))
+ (eobp)))
+ `((at-eof . t)))
(position . ,(or posn (point)))))
\f
@@ -1119,7 +1133,8 @@
(buf (bookmark-prop-get bmk-record 'buffer))
(forward-str (bookmark-get-front-context-string bmk-record))
(behind-str (bookmark-get-rear-context-string bmk-record))
- (place (bookmark-get-position bmk-record)))
+ (place (bookmark-get-position bmk-record))
+ (at-eof (bookmark-get-at-eof bmk-record)))
(set-buffer
(cond
((and file (file-readable-p file) (not (buffer-live-p buf)))
@@ -1128,16 +1143,18 @@
((and buf (get-buffer buf)))
(t ;; If not, raise error.
(signal 'bookmark-error-no-filename (list 'stringp file)))))
- (if place (goto-char place))
- ;; Go searching forward first. Then, if forward-str exists and
- ;; was found in the file, we can search backward for behind-str.
- ;; Rationale is that if text was inserted between the two in the
- ;; file, it's better to be put before it so you can read it,
- ;; rather than after and remain perhaps unaware of the changes.
- (when (and forward-str (search-forward forward-str (point-max) t))
- (goto-char (match-beginning 0)))
- (when (and behind-str (search-backward behind-str (point-min) t))
- (goto-char (match-end 0)))
+ (if at-eof
+ (goto-char (point-max))
+ (if place (goto-char place))
+ ;; Go searching forward first. Then, if forward-str exists and
+ ;; was found in the file, we can search backward for behind-str.
+ ;; Rationale is that if text was inserted between the two in the
+ ;; file, it's better to be put before it so you can read it,
+ ;; rather than after and remain perhaps unaware of the changes.
+ (when (and forward-str (search-forward forward-str (point-max) t))
+ (goto-char (match-beginning 0)))
+ (when (and behind-str (search-backward behind-str (point-min) t))
+ (goto-char (match-end 0))))
nil))
;;;###autoload
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
next reply other threads:[~2011-07-11 2:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-11 2:05 Daniel Colascione [this message]
2011-07-11 13:38 ` [PATCH] auto-EOF for bookmarks Drew Adams
2011-07-11 21:33 ` Karl Fogel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E1A5A62.3050906@gmail.com \
--to=dan.colascione@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.