From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: Listing markers in buffer Date: Sat, 30 Apr 2016 11:16:28 +0200 Organization: Informatimago Message-ID: <87r3dnv4lv.fsf@kuiper.lan.informatimago.com> References: <39ea9931-1237-48e2-ae24-a14e465a56d6@googlegroups.com> <871t5o1gp8.fsf@kuiper.lan.informatimago.com> <3b7d39b5-8fc6-4ceb-869b-691e27884cd0@googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1464881799 19831 80.91.229.3 (2 Jun 2016 15:36:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 2 Jun 2016 15:36:39 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 02 17:36:38 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1b8Ufj-0007a4-Eg for geh-help-gnu-emacs@m.gmane.org; Thu, 02 Jun 2016 17:36:35 +0200 Original-Received: from localhost ([::1]:48070 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Ufi-0007wx-M0 for geh-help-gnu-emacs@m.gmane.org; Thu, 02 Jun 2016 11:36:34 -0400 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 80 Original-X-Trace: individual.net /6H9My3YBRNGjoJullnzDAao7AslBJD/2uZcLR8sJiFT39x4Je Cancel-Lock: sha1:ZGI2MjYxYzljMjNkZmJkZGMwNTU4ZGRkMDhkYTA2ZjQ0OGE4MDBhYQ== sha1:Ty/xeRm3jGDowrfMJPGZkppLwm8= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:217572 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:110189 Archived-At: "ian.tegebo" writes: > On Friday, April 29, 2016 at 10:13:27 AM UTC-7, Pascal J. Bourguignon wrote: >> "ian.tegebo" writes: >> >> > Looking at the C source, I can see that buffer to buffer_text structs >> > point to a singly linked list of Lisp_marker structs [...] >> >> Markers belong to their owners, and it would be very dangerous if you >> could get them and set or reset them behind the back of their owners. > > Could you provide an example? > > Here's where I'm coming from: > > While writing a yas-snippet, I wanted to modify previous text > depending on some event within a field. I found that by doing so, it > broke because I didn't understand how overlays and markers were being > used [1]. Naively, I thought I could get a list of markers in the > buffer, like one can get the text properties and overlays for at least > the purposes of learning/debugging. Yes, for debugging it might be interesting to get them. > Instead, I read the code to determine exactly what was going on. In > retrospect, I might have saved myself some time if I'd have been able > to see the details of the markers in the affected region. Now, I see > where the markers are being held in yas-snippet, so I can still get at > them and muck about. > > When you say "dangerous", is it the same kind of danger I'm exposed to > when changing the internal state elisp libraries *in general*? Or do > you mean "danger" in a specific sense, e.g. that some monstrous GC bug > is hiding behind the scenes once a buffer's markers are exposed? > > [1]: I'm aware that this is a known no-no No, it's a little danger: you might break an invariant for some code, so it will do something wrong next time it's run, or at worse, signal an error (and possibly enter the debugger, with a puzzled used). However, little danger can grow big. Assume you have a package with two commands: executor-select-command executor-execute-selected-command You type a shell command in a buffer: ls -l select it and M-x executor-select-command RET This would put a pair of markers on the region, so that you can still edit it, eg. into ls -aFCNl and then M-x executor-execute-selected-command when you want to fork a shell with it (call shell-command). Now, if some code could get the list of markers, and move those marker to a (hidden) region containing: rm -rf / you would be in a dire situation. (if your code modified the existing region, the user would see it and hopefully wouldn't do M-x executor-execute-selected-command). That said, there may be "public" markers. They's stored in public variables, or packages may have functions to return them. M-x apropos RET markers RET gives a few of them, for example org-refile-markers or forms--markers. Perhaps yasnippet has such a list of public markers too? Or perhaps you could modify it to record and provide such a list? -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk