dotemacs

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

compat-help.el (2162B)


      1 ;;; compat-help.el --- Documentation for compat functions  -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2022  Free Software Foundation, Inc.
      4 
      5 ;; Author: Philip Kaludercic <philipk@posteo.net>
      6 
      7 ;; This program is free software; you can redistribute it and/or modify
      8 ;; it under the terms of the GNU General Public License as published by
      9 ;; the Free Software Foundation, either version 3 of the License, or
     10 ;; (at your option) any later version.
     11 
     12 ;; This program is distributed in the hope that it will be useful,
     13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 ;; GNU General Public License for more details.
     16 
     17 ;; You should have received a copy of the GNU General Public License
     18 ;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
     19 
     20 ;;; Commentary:
     21 
     22 ;; Load this file to insert `compat'-relevant documentation next to
     23 ;; the regular documentation of a symbol.
     24 
     25 ;;; Code:
     26 
     27 (defun compat---describe (symbol)
     28   "Insert documentation for SYMBOL if it has compatibility code."
     29   (let ((compat (get symbol 'compat-def)))
     30     (when compat
     31       (let ((doc (get compat 'compat-doc))
     32             (start (point)))
     33         (when doc
     34           (insert "There is a ")
     35           (insert-button
     36            "compatibility notice"
     37            'action (let ((type (get compat 'compat-type)))
     38                      (cond
     39                       ((memq type '(func macro advice))
     40                        #'find-function)
     41                       ((memq type '(variable))
     42                        #'find-variable)
     43                       ((error "Unknown type"))))
     44            'button-data compat)
     45           (insert (format " for %s (for versions of Emacs before %s):"
     46                           (symbol-name symbol)
     47                           (get compat 'compat-version)))
     48           (add-text-properties start (point) '(face bold))
     49           (newline 2)
     50           (insert (substitute-command-keys doc))
     51           (fill-region start (point))
     52           (newline 2))))))
     53 
     54 (add-hook 'help-fns-describe-function-functions #'compat---describe)
     55 
     56 (provide 'compat-help)
     57 ;;; compat-help.el ends here