From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: What happens with overlays when their buffer is killed? Date: Mon, 26 Mar 2018 18:44:04 +0200 Message-ID: <87zi2uzt1a.fsf@mbork.pl> References: <877epz1eoo.fsf@mbork.pl> <83k1tyg9mr.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1522082586 4437 195.159.176.226 (26 Mar 2018 16:43:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 26 Mar 2018 16:43:06 +0000 (UTC) User-Agent: mu4e 1.1.0; emacs 27.0.50 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Mar 26 18:43:02 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f0VD4-00014P-AS for geh-help-gnu-emacs@m.gmane.org; Mon, 26 Mar 2018 18:43:02 +0200 Original-Received: from localhost ([::1]:58023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0VF7-0006x4-Jw for geh-help-gnu-emacs@m.gmane.org; Mon, 26 Mar 2018 12:45:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58656) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0VEi-0006wZ-5n for help-gnu-emacs@gnu.org; Mon, 26 Mar 2018 12:44:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0VEh-0006MU-2f for help-gnu-emacs@gnu.org; Mon, 26 Mar 2018 12:44:44 -0400 Original-Received: from mail.mojserwer.eu ([195.110.48.8]:52551) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0VEc-0006Ka-GZ; Mon, 26 Mar 2018 12:44:38 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id A88FAE69DC; Mon, 26 Mar 2018 18:44:35 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id q__R5DAwbHt4; Mon, 26 Mar 2018 18:44:30 +0200 (CEST) Original-Received: from localhost (static-dwadziewiec-jedenpiec7.echostar.pl [109.232.29.157]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 9FD10E6700; Mon, 26 Mar 2018 18:44:30 +0200 (CEST) In-reply-to: <83k1tyg9mr.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.110.48.8 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:116283 Archived-At: On 2018-03-26, at 17:05, Eli Zaretskii wrote: >> From: Marcin Borkowski >> Date: Mon, 26 Mar 2018 09:25:27 +0200 >> >> assume that I create a few overlays in some buffer, and then I kill that >> buffer. What happens with the overlays? If they were not assigned to >> a variable, do they get garbage collected? > > They will be GC'ed on the next opportunity when Emacs decides to GC. Thanks, that's great! Here is my code displaying the size of the attachment in message-mode and highlighting the "important" parts of the mml tag. (I will probably write about it on my blog some day.) --8<---------------cut here---------------start------------->8--- (require 'cl) (defconst iec-prefixes ["" "Ki" "Mi" "Gi"]) (defun human-readable-size (size) "Return SIZE as human-readable string, using IEC prefixes." (let* ((order (1- (max 1 (ceiling (log (max size 1) 1024))))) (prefix (elt iec-prefixes (min order (length iec-prefixes)))) (size-in-unit (/ size (expt 1024.0 order))) (precision (max 3 (+ 2 (floor (log (max size-in-unit 1) 10))))) (size-str (format (format "%%.%dg%%sB" precision) size-in-unit prefix))) size-str)) (defun mml-add-size-to-message-part (name &rest plist) "Add filesize to the inserted part if applicable" (if (and (eq name 'part) (plist-member plist 'filename)) (plist-put plist 'size (number-to-string (file-attribute-size (file-attributes (plist-get plist filename)))))) (cons name plist)) (advice-add 'mml-insert-empty-tag :filter-args 'mml-add-size-to-message-part) (defun embolden-with-overlay (start end) "Embolden the text between START and END, using an overlay." (let ((tmp-overlay (make-overlay start end))) (overlay-put tmp-overlay 'face 'bold))) (defun make-mml-tag-before-point-more-legible (name &rest plist) "Apply boldface to relevant parts of mml tag before point." (save-excursion (let ((opoint (point))) (when (search-backward (format "<#%s" name) nil nil) (goto-char (match-end 0)) (while (looking-at " [a-z]+=") (goto-char (match-end 0)) (if (eq (char-after) ?\") (embolden-with-overlay (progn (forward-char) (point)) (progn (while (and (search-forward "\"" opoint t) (save-excursion (backward-char) (cl-oddp (skip-chars-backward "\\\\"))))) (point))) (embolden-with-overlay (point) (progn (re-search-forward "[ >]" opoint t) (backward-char) (point))))))))) (advice-add 'mml-insert-tag :after 'make-mml-tag-before-point-more-legible) --8<---------------cut here---------------end--------------->8--- Comments welcome. -- Marcin Borkowski http://mbork.pl