From: Jean Louis <bugs@gnu.support>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: "Daniel Martín" <mardani29@yahoo.es>, emacs-devel@gnu.org
Subject: Re: A feature to go to last edit locations
Date: Mon, 13 Feb 2023 22:24:02 +0300 [thread overview]
Message-ID: <Y+qOUhNiPvZcuStS@protected.localdomain> (raw)
In-Reply-To: <972bedcc-37c9-5180-ac41-90e25d854a63@yandex.ru>
* Dmitry Gutov <dgutov@yandex.ru> [2023-02-12 21:09]:
> On 12/02/2023 19:41, Daniel Martín wrote:
> > What do you think? Third-party packages like goto-last-change.el [2] or
> > session.el [3] (see session-jump-to-last-change) implement this feature
> > in a per-buffer basis, but I wonder if we could do better and implement
> > something that works across buffers.
>
> I agree this kind of feature should work across buffers (and that's my main
> criticism of the global/local marks feature already).
I was reading, thanks, it inspired me.
But Eli said something important, why go somewhere back randomly, but
better going where user marked it to need it.
Now I get it with single click: S-C-<down> to record point and then
S-C-<left> and <right> to go to previous or next one.
It is using database, but it may serve for brainstorming. I also try
to use database tables to switch to them, instead of buffers with
files.
Emacs has SQLite built-in, this way of work could be used in future,
or package could easily be made.
It would persist over sessions without problems.
And I could make a switch that instead of moving over global points,
and buffers, to move only in single buffer.
(defvar rcd-db-emacs-point-id nil
"Last Emacs point ID where user jumped to.")
(defun rcd-db-emacs-point-next ()
"Go to next Emacs point."
(interactive)
(let ((next (rcd-db-emacs-point-to-go "next")))
next))
(defun rcd-db-emacs-point-previous ()
"Go to previous Emacs point."
(interactive)
(let ((previous (rcd-db-emacs-point-to-go "previous")))
previous))
(defun rcd-db-emacs-point-go-to (id)
"Go to Emacs point ID."
(let ((point (rcd-db-table-id-hash "emacspoints" id cf-db)))
(when (hash-table-keys point)
(let ((buffer-name (gethash "emacspoints_buffername" point))
(file-name (gethash "emacspoints_bufferfilename" point))
(table (gethash "emacspoints_table" point))
(column (gethash "emacspoints_column" point))
(table-id (gethash "emacspoints_tableid" point))
(point (gethash "emacspoints_point" point)))
(cond ((and buffer-name
(buffer-live-p (get-buffer buffer-name))
(not file-name)
(not table))
(switch-to-buffer buffer-name)
(goto-char point))
((and buffer-name file-name
(buffer-live-p (get-buffer buffer-name))
(not table))
(switch-to-buffer buffer-name)
(goto-char point))
((and buffer-name file-name
(not (buffer-live-p (get-buffer buffer-name)))
(not table))
(find-file file-name)
(goto-char point))
((and buffer-name table column table-id
(buffer-live-p (get-buffer buffer-name)))
(switch-to-buffer buffer-name)
(goto-char point))
((and buffer-name table column table-id
(not (buffer-live-p (get-buffer buffer-name))))
(hyperscope-edit-with-mode table-id column)
(switch-to-buffer buffer-name)
(goto-char point))
(t (rcd-message "Point ID %s not found" id)))))))
(keymap-global-set "M-s-<left>" #'rcd-db-emacs-point-previous)
(keymap-global-set "M-s-<right>" #'rcd-db-emacs-point-next)
(keymap-global-set "M-s-<down>" #'rcd-db-emacs-point-record)
(defun rcd-db-emacs-point-to-go (direction)
"Return next Emacs point to go by using DIRECTION.
DIRECTION is string that may be \"previous\" or \"next\"."
(when (string-match "^next$\\|^previous$" direction)
(let ((last (rcd-sql-first "SELECT emacspoints_id FROM emacspoints ORDER BY emacspoints_id DESC LIMIT 1" cf-db))
(first (rcd-sql-first "SELECT emacspoints_id FROM emacspoints ORDER BY emacspoints_id ASC LIMIT 1" cf-db))
(message (format "No %s point found" direction))
(next (when (integerp rcd-db-emacs-point-id)
(rcd-sql-first
"SELECT emacspoints_id FROM emacspoints WHERE emacspoints_id > $1 ORDER BY emacspoints_id ASC LIMIT 1"
cf-db rcd-db-emacs-point-id)))
(previous (when (integerp rcd-db-emacs-point-id)
(rcd-sql-first
"SELECT emacspoints_id FROM emacspoints WHERE emacspoints_id < $1 ORDER BY emacspoints_id DESC LIMIT 1"
cf-db rcd-db-emacs-point-id))))
(cond ((and (string= direction "previous")
rcd-db-emacs-point-id
previous)
(rcd-db-emacs-point-go-to
(setq rcd-db-emacs-point-id previous)))
((and (string= direction "previous")
rcd-db-emacs-point-id
(null previous)
last)
(rcd-db-emacs-point-go-to
(setq rcd-db-emacs-point-id last)))
((and (string= direction "previous")
rcd-db-emacs-point-id
(null previous)
(null last))
(rcd-message message))
((and (string= direction "next")
rcd-db-emacs-point-id
next)
(rcd-db-emacs-point-go-to
(setq rcd-db-emacs-point-id next)))
((and (string= direction "next")
rcd-db-emacs-point-id
(null next)
first)
(rcd-db-emacs-point-go-to
(setq rcd-db-emacs-point-id first)))
(t (rcd-message message))))))
(defun rcd-db-emacs-point-record ()
"Record Emacs point in the database."
(interactive)
(let* ((buffer-name (buffer-name))
(file-name (buffer-file-name))
(table rcd-db-current-table)
(column rcd-db-current-column)
(table-id rcd-db-current-table-id)
(db-handle rcd-db-current-database-handle)
(db-name (cond ((and db-handle (rcd-sql-first "SELECT current_database()" db-handle))
(t nil))))
(point (point))
(name (cond (current-prefix-arg (rcd-ask-get "Point name: "))
(table (format "DB: %s, table: %s, column: %s, ID: %s"
db-name table column table-id))
((not file-name) (format "Buffer: %s" buffer-name))
(t (format "File: %s" file-name))))
(description (cond (current-prefix-arg (sql-escape-string (rcd-ask "Point description: ")))
(t "NULL")))
(table-uuid (when (and table-id
(rcd-db-uuid-by-id table table-id cf-db))
(rcd-db-uuid-by-id table table-id cf-db))))
(rcd-sql-first
(format "INSERT INTO emacspoints
(emacspoints_name, emacspoints_description, emacspoints_buffername, emacspoints_bufferfilename, emacspoints_dbname,
emacspoints_table, emacspoints_column, emacspoints_tableid, emacspoints_tableuuid, emacspoints_point)
VALUES ($1, %s, $2, %s, %s, %s, %s, %s, %s, $3)
ON CONFLICT DO NOTHING
RETURNING emacspoints_id" description
(sql-escape-string-or-null file-name) (sql-escape-string-or-null db-name)
(sql-escape-string-or-null table) (sql-escape-string-or-null column) (or table-id "NULL")
(sql-escape-string-or-null table-uuid))
cf-db name buffer-name point)))
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
next prev parent reply other threads:[~2023-02-13 19:24 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <m1fsbakchr.fsf.ref@yahoo.es>
2023-02-12 17:41 ` A feature to go to last edit locations Daniel Martín
2023-02-12 17:52 ` Eli Zaretskii
2023-02-12 18:59 ` Daniel Martín
2023-02-12 19:26 ` Eli Zaretskii
2023-02-12 19:42 ` andrés ramírez
2023-02-12 22:19 ` Daniel Martín
2023-02-12 23:54 ` Dr. Arne Babenhauserheide
2023-02-13 7:50 ` Juri Linkov
2023-02-12 21:40 ` [External] : " Drew Adams
2023-02-13 20:28 ` Jean Louis
2023-02-12 18:07 ` Dmitry Gutov
2023-02-12 18:50 ` Daniel Martín
2023-02-12 18:52 ` Dmitry Gutov
2023-02-12 19:23 ` Daniel Martín
2023-02-13 19:28 ` Jean Louis
2023-02-13 19:24 ` Jean Louis [this message]
2023-02-13 19:41 ` Dmitry Gutov
2023-02-13 20:22 ` Dr. Arne Babenhauserheide
2023-02-13 20:56 ` Jean Louis
2023-02-14 3:25 ` Eli Zaretskii
2023-02-14 4:36 ` [External] : " Drew Adams
2023-02-14 4:56 ` Drew Adams
2023-02-14 5:53 ` Jean Louis
2023-02-14 16:24 ` Drew Adams
2023-02-15 5:45 ` Jean Louis
2023-02-15 16:34 ` Drew Adams
2023-02-16 8:17 ` On Bookmarks+ package Jean Louis
2023-02-16 17:38 ` [External] : " Drew Adams
2023-02-14 20:08 ` A feature to go to last edit locations Dmitry Gutov
2023-02-13 19:48 ` [External] : " Drew Adams
2023-02-13 20:28 ` Dr. Arne Babenhauserheide
2023-02-13 21:17 ` Drew Adams
2023-02-13 21:21 ` Jean Louis
2023-02-13 21:14 ` Jean Louis
2023-02-14 5:21 ` Drew Adams
2023-02-13 19:49 ` Michael Welsh Duggan
2023-02-13 21:35 ` Jean Louis
2023-02-13 23:14 ` Konstantin Kharlamov
2023-02-14 0:00 ` Ergus
2023-02-14 6:29 ` Dr. Arne Babenhauserheide
2023-02-15 0:00 ` Karthik Chikmagalur
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=Y+qOUhNiPvZcuStS@protected.localdomain \
--to=bugs@gnu.support \
--cc=dgutov@yandex.ru \
--cc=emacs-devel@gnu.org \
--cc=mardani29@yahoo.es \
/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.