Temporary notes in Emacs buffers?

classic Classic list List threaded Threaded
59 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: Temporary notes in Emacs buffers?

Marcin Borkowski-3

On 2019-12-27, at 16:54, Drew Adams <[hidden email]> wrote:

>> I've been wondering if there is some package which could let me make
>> "temporary notes" in Emacs buffers, similar to (but different than) the
>> "yellow notes" in some pdf viewers.
>>
>> My use case is that I'm making a sweeping change across a pretty large
>> codebase, and I'd like to make some notes in places I've already
>> visited
>> / ones I need to change / etc.
>>
>> At present, I use normal code comments, however, this is suboptimal,
>> since I cannot use them in certain modes (occur buffer, JSON).
>>
>> Ideally, a place with a comment would have that comment highlighted
>> somehow, and I should be able to go to the next/previous comment, and
>> list all comments in a file or in the project (think Git repo,
>> Projectile project or a directory tree).  Also, mass inserting such
>> comments from an occur/multi-occur/projectile-ag/counsel-rg/etc.
>> buffers
>> would be great.
>>
>> What I /don't/ want is modifying the files - the comments might persist
>> in some /other/, .gitignore-d file, or just disappear on exiting Emacs.
>>
>> I know bookmark+ has similar features, but I'd prefer something more
>> lightweight.
>>
>> Does there exist something like that?  Am I the only one interested in
>> such a feature?  (I'd be happy to code it myself, though it would take
>> time, of course.)
>
> Vanilla Emacs bookmarks provide the ability to annotate.
> Bookmark+ enhances annotating (e.g. to use Org and
> indirection), but the annotation provided by vanilla
> Emacs bookmarking does what you requested.

Thanks, I'll check it out.

--
Marcin Borkowski
http://mbork.pl

Reply | Threaded
Open this post in threaded view
|

Re: Temporary notes in Emacs buffers?

Michael Heerdegen
In reply to this post by Drew Adams
Drew Adams <[hidden email]> writes:

> I guess you mean just what you said before: You
> want to be able to move a file, and some bookmarks
> that target it, to a different directory, and have
> the bookmarks continue to work there.

Yes.

> > names.  You are sure that there is no predefined way to use relative
> > names?

> You can define a bookmark handler for any type of
> bookmark.  The handler could ignore the directory
> part of the recorded file name, and get the needed
> directory from somewhere else, e.g., from a global
> variable or a function.  (It has to come from
> somewhere.)  E.g., a variable could have an alist
> value with keys for your different whatevers (even
> nondir-filename keys) and with dirs as the values.
>
> But then you'd have to update the variable value
> when you move the targeted files.  As I said before,
> you can write code that does something like that
> [...]

Can't I just use a file or directory local variable for that part?  That
would be a trivial solution for the problem.

The problem is that the bookmark file can't know where I may have moved
a file to -- but I'm very unlikely to move the bookmark file very often.
So I would prefer a solution where the file knows where to ask for its
bookmarks and annotations, and the bookmark mechanism has the data and
the mean to deliver it.

Michael.

Reply | Threaded
Open this post in threaded view
|

Re: Temporary notes in Emacs buffers?

John Yates-4
This broaches the question of what is being annotated,
the file as a container (e.g. inode) or its contents:

   1. What happens when one moves the file?
   2. What happens when one copies the file?
   3. What if after the copy one deletes the original?

My sense is that this thread is most concerned with use
case number 1.

An approach not yet mentioned is including some form of
UUID as a file local variable.  In such a setting notes
indirect through a persistent UUID-to-path map.  A file
handler recognizes relevant operations on UUID annotated
and updates the map.  This might also include updating
the new copy's UUID to preserve uniqueness.

/john
Reply | Threaded
Open this post in threaded view
|

RE: Temporary notes in Emacs buffers?

Drew Adams
 

This broaches the question of what is being annotated,
the file as a container (e.g. inode) or its contents

 

If we're still talking about bookmarks, then either one can be the target. To get to the content you first get to the container. But there's no requirement that you target any of the content. A bookmark can act in any way you like on a file, as container, without having anything to do with the content. A bookmark's handler is just a function.

What happens when one moves the file?
What happens when one copies the file?
What if after the copy one deletes the original?

My sense is that this thread is most concerned with use
case number 1.

An approach not yet mentioned is including some form of
UUID as a file local variable.  In such a setting notes
indirect through a persistent UUID-to-path map.  A file
handler recognizes relevant operations on UUID annotated
and updates the map.  This might also include updating
the new copy's UUID to preserve uniqueness.

If Emacs gives you a way to get to a file by an UUID that doesn't change when you move the file, then you could use that in a bookmark. That might, indeed, be a good answer. I don't know that Emacs provides such a way (how?). (You can get the inode of a file, but can you find a file, given its inode?)
Reply | Threaded
Open this post in threaded view
|

RE: Temporary notes in Emacs buffers?

Drew Adams
In reply to this post by Michael Heerdegen
> > You can define a bookmark handler for any type of
> > bookmark.  The handler could ignore the directory
> > part of the recorded file name, and get the needed
> > directory from somewhere else, e.g., from a global
> > variable or a function.  (It has to come from
> > somewhere.)
> >
> > E.g., a variable could have an alist
> > value with keys for your different whatevers (even
> > nondir-filename keys) and with dirs as the values.
> >
> > But then you'd have to update the variable value
> > when you move the targeted files.  As I said before,
> > you can write code that does something like that [...]
>
> Can't I just use a file or directory local variable
> for that part? That would be a trivial solution
> for the problem.

You can.  I think I mentioned that.  You can put
the new location of the file anywhere you like,
for a bookmark to pick up and use.

Is it trivial for you to update a variable value
whenever you move the target file?  If so, then
Bob's your uncle - just use a bookmark handler
that uses the variable value to provide the dir.

The point is that the code that handles a bookmark
has to get that info from somewhere.

Currently it gets it from the bookmark (as an
absolute file name), but it could get it anywhere.

If you're sure to be in the same dir as the target
file when you use a bookmark to it, then you can
have the handler just use `default-directory' - no
need for any variable or whatever.

If not, but if some other rule applies for knowing
the location of the file relative to the place
where you invoke the bookmark, then you can code
that in the handler.

If not - e.g., if you put the new location in a
var or whatever, then the handler can get it there.

There's no miracle.  The bookmark is separate from
the target file.  As a consequence, you need to
provide some connection between the two, which
will remain valid when you move the file - a rule,
a lookup,... - something.

> The problem is that the bookmark file can't know
> where I may have moved a file to

Bookmark, not bookmark file.  It's not about
the bookmark file.  (I may have misspoken and
given the wrong impression about that.)

If the bookmark you invoke can assume that the
target file will always be in some location
relative to where it's invoked (e.g. same dir),
or if the file location can be obtained somehow,
then there's no problem - how to obtain it just
needs to be coded in the bookmark's handler.

If the handler can assume that the file's dir
will always be in some variable, or obtainable
by some function, then it can use that info.

> -- but I'm very unlikely to move the bookmark
> file very often.

It's not about where the bookmark file is.
It's about how the bookmark is accessed (from
where), and how it gets the target location.

> So I would prefer a solution where the file
> knows where to ask for its bookmarks and
> annotations, and the bookmark mechanism has
> the data and the mean to deliver it.

See above.  It's up to you to define that
mechanism - how "the file knows" and "asks".

Various means are available for linking the
bookmark and its target file logically.  But
they do need to be linked, in some way.  How
you do that depends on your use case.  I can
only say that, because the bookmark and its
target file are separate, some linkage is
needed.

---

I suggest that the general discussion of
your and Marcin's questions be continued in
this thread, and that if there's a more
detailed discussion to be had about how to
do what you want using bookmarks we do that
off-list, as it might be a distraction.
Just a suggestion.

Reply | Threaded
Open this post in threaded view
|

RE: Temporary notes in Emacs buffers?

Drew Adams
In reply to this post by John Yates-4
[Sending my reply again, as the HTML reply
made no distinction (that I can see in my
email client) between what you wrote and
what I replied.]

> This broaches the question of what is being annotated,
> the file as a container (e.g. inode) or its contents

If we're still talking about bookmarks, then
either one can be the target.  To get to the
content you first get to the container.  But
there's no requirement that you target any
of the content.  A bookmark can act in any
way you like on a file, as container, without
having anything to do with the content.
A bookmark's handler is just a function.

> 1. What happens when one moves the file?
> 2. What happens when one copies the file?
> 3. What if after the copy one deletes the original?
>
> My sense is that this thread is most concerned
> with use case number 1.
>
> An approach not yet mentioned is including some
> form of UUID as a file local variable.  In such
> a setting notes indirect through a persistent
> UUID-to-path map.  A file handler recognizes
> relevant operations on UUID annotated and
> updates the map.  This might also include
> updating the new copy's UUID to preserve
> uniqueness.

If Emacs gives you a way to get to a file
by an UUID that doesn't change when you
move the file, then you could use that in
a bookmark. That might, indeed, be a good
answer. I don't know that Emacs provides
such a way (how?). (You can get the inode
of a file, but can you find a file, given
its inode?)

Reply | Threaded
Open this post in threaded view
|

RE: Temporary notes in Emacs buffers?

arthur miller
In reply to this post by Michael Heerdegen
Interesting discussion.

To me it is clear that any solution to a file format, such as plain ascii text, is going to be external to annotated file itself. Whatever you use, Drew's bookmarks+, file- or dir-local, or some other custom. An external solution implies that you will have your annotation in different place then file itself which you will have to take care off with backups, moving etc. You could automate that by implementing some kind of file handler as Drew suggested some day ago. You can implement something in Emacs as a hook to file save and/or dired machinery or if you are on Gnu/linux you could use inotify.

Otherwise there is Org, you can use org mode (or something similar) and implement your annotations as references or hyperlinks or something else. That would turn your text file into org text file.

There is also some org annotation mode that won't change your original text fil:

https://www.emacswiki.org/emacs/OrgAnnotateFile

 but with same problem of having annotation separated from the original file.

Skickat från min Samsung Galaxy-smartphone.



-------- Originalmeddelande --------
Från: Michael Heerdegen <[hidden email]>
Datum: 2020-01-03 02:08 (GMT+01:00)
Till: Drew Adams <[hidden email]>
Kopia: Help Gnu Emacs mailing list <[hidden email]>
Ämne: Re: Temporary notes in Emacs buffers?

Drew Adams <[hidden email]> writes:

> I guess you mean just what you said before: You
> want to be able to move a file, and some bookmarks
> that target it, to a different directory, and have
> the bookmarks continue to work there.

Yes.

> > names.  You are sure that there is no predefined way to use relative
> > names?

> You can define a bookmark handler for any type of
> bookmark.  The handler could ignore the directory
> part of the recorded file name, and get the needed
> directory from somewhere else, e.g., from a global
> variable or a function.  (It has to come from
> somewhere.)  E.g., a variable could have an alist
> value with keys for your different whatevers (even
> nondir-filename keys) and with dirs as the values.
>
> But then you'd have to update the variable value
> when you move the targeted files.  As I said before,
> you can write code that does something like that
> [...]

Can't I just use a file or directory local variable for that part?  That
would be a trivial solution for the problem.

The problem is that the bookmark file can't know where I may have moved
a file to -- but I'm very unlikely to move the bookmark file very often.
So I would prefer a solution where the file knows where to ask for its
bookmarks and annotations, and the bookmark mechanism has the data and
the mean to deliver it.

Michael.

Reply | Threaded
Open this post in threaded view
|

Re: Temporary notes in Emacs buffers?

Michael Heerdegen
In reply to this post by John Yates-4
John Yates <[hidden email]> writes:

> An approach not yet mentioned is including some form of
> UUID as a file local variable.  In such a setting notes
> indirect through a persistent UUID-to-path map.  A file
> handler recognizes relevant operations on UUID annotated
> and updates the map.  This might also include updating
> the new copy's UUID to preserve uniqueness.

But Emacs would have to prompt, because if the copy is meant as backup,
the UUID shouldn't be changed.  And if I happen to not use Emacs (but
e.g. rsync) those handlers would not run, right?

Michael.

Reply | Threaded
Open this post in threaded view
|

RE: Temporary notes in Emacs buffers?

Drew Adams
> > An approach not yet mentioned is including some form of
> > UUID as a file local variable.  In such a setting notes
> > indirect through a persistent UUID-to-path map.  A file
> > handler recognizes relevant operations on UUID annotated
> > and updates the map.  This might also include updating
> > the new copy's UUID to preserve uniqueness.
>
> But Emacs would have to prompt, because if the copy is meant as backup,
> the UUID shouldn't be changed.  And if I happen to not use Emacs (but
> e.g. rsync) those handlers would not run, right?

My question about this is (still) how do you use
`find-file' (or something else) to open a file
for editing, given just the inode/UUID?

Such a thing could be recorded in a bookmark,
but how to use it, to get to the file, with
Emacs?

Reply | Threaded
Open this post in threaded view
|

Re: Temporary notes in Emacs buffers?

Michael Heerdegen
In reply to this post by arthur miller
arthur miller <[hidden email]> writes:

> There is also some org annotation mode that won't change your original
> text fil:
>
> https://www.emacswiki.org/emacs/OrgAnnotateFile
>
>  but with same problem of having annotation separated from the
> original file.

Does that package offer to attach the notes to a certain position in a
file?  Seems not to be the case.  But it's still nice.


Thanks,

Michael.

Reply | Threaded
Open this post in threaded view
|

Re: Temporary notes in Emacs buffers?

Michael Heerdegen
In reply to this post by Drew Adams
Drew Adams <[hidden email]> writes:

> Vanilla Emacs bookmarks provide the ability to annotate.
> Bookmark+ enhances annotating (e.g. to use Org and
> indirection), but the annotation provided by vanilla
> Emacs bookmarking does what you requested.

Do Vanilla bookmarks really recognize automatically when a bookmarked
position has changed because the user has inserted some preceding text?
I mean, I know bookmarks save surrounding text to work around that
problem but that works only by luck most of the time.  Same question for
highlighting bookmarked positions: I thought such features were only
added by "bookmark+"?

Michael.

Reply | Threaded
Open this post in threaded view
|

RE: Temporary notes in Emacs buffers?

Drew Adams
> > Vanilla Emacs bookmarks provide the ability to annotate.
> > Bookmark+ enhances annotating (e.g. to use Org and
> > indirection), but the annotation provided by vanilla
> > Emacs bookmarking does what you requested.

(Note: That statement is only about annotating.
Your response is about automatic relocation and
highlighting.)

> Do Vanilla bookmarks really recognize automatically
> when a bookmarked position has changed because the
> user has inserted some preceding text?  I mean, I
> know bookmarks save surrounding text to work around that
> problem but that works only by luck most of the time.

Yes.  I don't think it works only by luck most of
the time.  I think it works well most of the time.

Of course, if there are large edits before the
next time you jump to a bookmark, then, yes, it
might not be possible to relocate it automatically
(in which case you're prompted to relocate it
manually).

But edits between jumps to a bookmark are, I think,
typically not so large as to prevent automatic
relocating.

Also, the automatic relocation of Bookmark+ is
better than that of vanilla Emacs.

> Same question for highlighting bookmarked positions:
> I thought such features were only added by "bookmark+"?

Correct.  That is added by Bookmark+.  It's not
available with vanilla bookmark handling.

If you use Bookmark+ then the highlighting is
available also for bookmarks created with vanilla
Emacs.  But the highlighting is not available
without Bookmark+.

Reply | Threaded
Open this post in threaded view
|

Re: Temporary notes in Emacs buffers?

Jean-Christophe Helary-4


> On Jan 6, 2020, at 2:54, Drew Adams <[hidden email]> wrote:
>
> If you use Bookmark+ then the highlighting is
> available also for bookmarks created with vanilla
> Emacs.  But the highlighting is not available
> without Bookmark+.

I am not seeing Bookmark+ in Melpa, is it only on EmacsWiki ?

Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune



Reply | Threaded
Open this post in threaded view
|

Re: Temporary notes in Emacs buffers?

John Yates-4
In reply to this post by Drew Adams
On Sat, Jan 4, 2020 at 11:05 AM Drew Adams <[hidden email]> wrote:

> > An approach not yet mentioned is including some form of
> > UUID as a file local variable.  In such a setting notes
> > indirect through a persistent UUID-to-path map.  A file
> > handler recognizes relevant operations on UUID annotated
> > and updates the map.  This might also include updating
> > the new copy's UUID to preserve uniqueness.
>
> My question about this is (still) how do you use
> `find-file' (or something else) to open a file
> for editing, given just the inode/UUID?
>
> Such a thing could be recorded in a bookmark,
> but how to use it, to get to the file, with
> Emacs?

This is rather half baked.  It combined ideas from Gnu arch and
Apollo Computer's distributed file system.  The common thread is
the idea of a UUID.

The Gnu arch DVCS embedded the UUID in the text of a file being
managed (essentially an elisp file local variable).  This was
crucial to supporting renaming.

An Apollo UUID contained the equivalent of the MAC address for
the node which first handed out that UUID.  UUIDs were used in
many ways and many APIs.  In particular the UUID replaced an
inode index.  This made the ID of a file container universal
rather than file system relative.  The equivalent of the inode
table was a persistent hash table indexed by UUID.

File lookup by UUID was not only supported but fundamental:
directories were mapping from names to UUIDs.

Simplified file open by UUID:

  First: attempt local open:
  * Probe local file system's hash table using UUID as key
  * If found return a local file connection

  Fallback: attempt remote open:
  * Extract MAC address from UUID
  * If self then return file-not-found
  * Use MAC address to talk to node that issued that UUID
  * Ask that node to open a file by UUID
  * Remote node performs only the local half of file open
  * If found return a cross-network remote file connection

  Otherwise return file-not-found

The above works up until one allows UUID identified objects to
migrate across nodes.  To support such use cases Apollo added a
redirection service.  The idea was that any node that allowed a
UUID containing its own MAC address to be exposed on another node
was responsible for tracking that UUID.  Persisting a foreign
UUID involved first obtaining permission from the source node's
redirection service.  This allowed the source node to record
whither its UUID had migrated.  With the redirection service in
place prior to probing the local file system's hash table for a
local UUID one would ask the redirection service whether the
presented UUID had been migrated.  If so the result was a
redirect status identifying the node now hosting that UUID.

If any of that makes sense then perhaps some of the ideas can
be turned into a design using a persistent UUID-to-path map to
associate notes to files identified by an embedded UUID.

/john

Reply | Threaded
Open this post in threaded view
|

Re: Temporary notes in Emacs buffers?

Tomas Zerolo
On Mon, Jan 06, 2020 at 09:18:56AM -0500, John Yates wrote:

[...]

> An Apollo UUID contained the equivalent of the MAC address for
[...]

Thanks for this enjoyable history lesson!

I didn't know that this MAC-in-UUID thing originated in
Apollo  (and din't know why it was there: now it makes
sense). I just took it for one of those typical Microsoft
messups.

The MAC-in-UUID is now mostly gone, for privacy reasons,
and perhaps even obsolete, with mobile devices rolling
their dice each time they need an UUID.

But yes, tracking files around is an iteresting problem
in itself, digging up even more interesting philosophical
questions (and technical, of course).

Cheers
-- tomás

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: Temporary notes in Emacs buffers?

Drew Adams
In reply to this post by Jean-Christophe Helary-4
> I am not seeing Bookmark+ in Melpa, is it only on EmacsWiki ?

Yes.

Reply | Threaded
Open this post in threaded view
|

Re: Temporary notes in Emacs buffers?

John Yates-4
In reply to this post by Tomas Zerolo
Tomás,

Paul Leach was responsible for the UUID's importance in Apollo's
architecture.  (Back
then it was called simply a UID.)  Paul was an early PhD student under
future von
Neumann medal and Turing award winner Barbara Liskov.  He was the most visionary
of the Apollo architects.  When Apollo got steamrolled by Sun Bill
Gates personally
recruited Paul to move to Microsoft.

You can learn more about Apollo's architecture here:

http://bitsavers.trailing-edge.com/pdf/apollo/Apollo_DOMAIN_Architecture_Feb81.pdf
http://bitsavers.trailing-edge.com/pdf/apollo/AEGIS_Overview_1985.pdf
http://bitsavers.trailing-edge.com/pdf/apollo/AEGIS_Internals_and_Data_Structures_Jan86.pdf

/john

Reply | Threaded
Open this post in threaded view
|

Re: Temporary notes in Emacs buffers?

Tomas Zerolo
On Mon, Jan 06, 2020 at 10:19:41AM -0500, John Yates wrote:
> Tomás,

Wow -- thanks :)

Cheers
-- t

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Temporary notes in Emacs buffers?

arthur miller
In reply to this post by John Yates-4
John Yates <[hidden email]> writes:

> Tomás,
>
> Paul Leach was responsible for the UUID's importance in Apollo's
> architecture.  (Back
> then it was called simply a UID.)  Paul was an early PhD student under
> future von
> Neumann medal and Turing award winner Barbara Liskov.  He was the most visionary
> of the Apollo architects.  When Apollo got steamrolled by Sun Bill
> Gates personally
> recruited Paul to move to Microsoft.
>
> You can learn more about Apollo's architecture here:
>
> http://bitsavers.trailing-edge.com/pdf/apollo/Apollo_DOMAIN_Architecture_Feb81.pdf
> http://bitsavers.trailing-edge.com/pdf/apollo/AEGIS_Overview_1985.pdf
> http://bitsavers.trailing-edge.com/pdf/apollo/AEGIS_Internals_and_Data_Structures_Jan86.pdf
>
> /john

Wow, thanks for the writings about Apollo and links!
Reply | Threaded
Open this post in threaded view
|

Re: Temporary notes in Emacs buffers?

Michael Heerdegen
In reply to this post by Drew Adams
Drew Adams <[hidden email]> writes:

> > I am not seeing Bookmark+ in Melpa, is it only on EmacsWiki ?
>
> Yes.

And AFAIK, Melpa can't fetch from Emacs wiki, AFAIR that's the
underlying problem.

Michael.

123