dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

sly-common.el (2629B)


      1 ;;; sly-common.el --- common utils for SLY and its contribs  -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2016  João Távora
      4 
      5 ;; Author: João Távora <joaotavora@gmail.com>
      6 ;; Keywords: 
      7 
      8 ;; This program is free software; you can redistribute it and/or modify
      9 ;; it under the terms of the GNU General Public License as published by
     10 ;; the Free Software Foundation, either version 3 of the License, or
     11 ;; (at your option) any later version.
     12 
     13 ;; This program is distributed in the hope that it will be useful,
     14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 ;; GNU General Public License for more details.
     17 
     18 ;; You should have received a copy of the GNU General Public License
     19 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
     20 
     21 ;;; Commentary:
     22 
     23 ;; Common utilities for SLY and its contribs
     24 
     25 ;;; Code:
     26 (require 'cl-lib)
     27 
     28 (defun sly--call-refreshing (buffer
     29                               overlay
     30                               dont-erase
     31                               recover-point-p
     32                               flash-p
     33                               fn)
     34   (with-current-buffer buffer
     35     (let ((inhibit-point-motion-hooks t)
     36           (inhibit-read-only t)
     37           (saved (point)))
     38       (save-restriction
     39         (when overlay
     40           (narrow-to-region (overlay-start overlay)
     41                             (overlay-end overlay)))
     42         (unwind-protect
     43             (if dont-erase
     44                 (goto-char (point-max))
     45               (delete-region (point-min) (point-max)))
     46           (funcall fn)
     47           (when recover-point-p
     48             (goto-char saved)))
     49         (when flash-p
     50           (sly-flash-region (point-min) (point-max)))))
     51     buffer))
     52 
     53 (cl-defmacro sly-refreshing ((&key
     54                               overlay
     55                               dont-erase
     56                               (recover-point-p t)
     57                               flash-p
     58                               buffer)
     59                              &rest body)
     60   "Delete a buffer region and run BODY which presumably refreshes it.
     61 Region is OVERLAY or the whole buffer.
     62 Recover point position if RECOVER-POINT-P.
     63 Flash the resulting region if FLASH-P"
     64   (declare (indent 1)
     65            (debug (sexp &rest form)))
     66   `(sly--call-refreshing ,(or buffer
     67                               `(current-buffer))
     68                          ,overlay
     69                          ,dont-erase
     70                          ,recover-point-p
     71                          ,flash-p
     72                          #'(lambda () ,@body)))
     73 
     74 
     75 (provide 'sly-common)
     76 ;;; sly-common.el ends here