From: "Clément Pit--Claudel" <clement.pit@gmail.com>
To: emacs-devel@gnu.org
Subject: Re: Paragraph styles in doc strings
Date: Mon, 20 Jun 2016 15:11:50 -0400 [thread overview]
Message-ID: <57683FF6.9020100@gmail.com> (raw)
In-Reply-To: <jwvbn3kjsvu.fsf-monnier+gmane.emacs.devel@gnu.org>
[-- Attachment #1.1.1: Type: text/plain, Size: 619 bytes --]
On 2016-06-01 21:18, Stefan Monnier wrote:
>> I'm not sure font-lock will work nicely for this. Blank lines are
>> a multi-line pattern.
>
> Actually, no, "^\n" is not a multi-line pattern (yes, it's right there
> on the border, but it's on the right side of the fence).
Thanks, that's neat!
> Oh, I'm not so concerned about the *Help* buffers, it's the source code
> that annoys me (that's where I work and where I don't want to waste
> screen real-estate).
Ok, I understand the purpose more clearly now :) What do you think of the attached package? If it works, I can push it to ELPA.
Clément.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: compact-docstrings.el --]
[-- Type: text/x-emacs-lisp; name="compact-docstrings.el", Size: 3424 bytes --]
;;; compact-docstrings.el --- Shrink blank lines in docstrings and doc comments
;; Copyright (C) 2016 Clément Pit-Claudel
;; Author: Clément Pit-Claudel <clement.pitclaudel@live.com>
;; URL: https://github.com/cpitclaudel/compact-docstrings
;; Package-Version: 0.1
;; Keywords: convenience, faces, lisp, maint, c
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Shrink blank lines in docstrings and doc comments
;;
;; Enable locally with `compact-docstrings-mode':
;; (add-hook 'some-mode-hook #'compact-docstrings-mode)
;;
;; Enable globally (in all programming modes) with
;; (add-hook 'after-init-hook #'global-compact-docstrings--mode)
;;; Code:
(defgroup compact-docstrings nil
"Shrink empty lines in docstrings and doc comments."
:group 'faces)
(defface compact-docstrings-face
'((t :height 0.5))
"Face applied to blank lines in docstrings."
:group 'compact-docstrings)
(defcustom compact-docstrings-only-doc-blocks t
"When nil, also shrink blank lines in regular strings and comments."
:group 'compact-docstrings
:type 'boolean)
(defun compact-docstrings--matcher (bound)
"Find blank line in docstring, looking in point .. BOUND."
(let ((found nil))
(while (and (not found) (re-search-forward "^\\s-*\n" bound t))
(let ((syntax (syntax-ppss)))
(when (and (or (nth 3 syntax) ;; In string
(nth 4 syntax)) ;; In comment
(or (not compact-docstrings-only-doc-blocks)
(let ((face (get-text-property (point) 'face)))
(or (eq face 'font-lock-doc-face)
(and (listp face) (memq 'font-lock-doc-face face))))))
(setq found t))))
found))
(defconst compact-docstrings--keywords
'((compact-docstrings--matcher 0 'compact-docstrings-face prepend)) 'append)
;;;###autoload
(define-minor-mode compact-docstrings-mode
"Shrink empty lines in docstrings and doc comments."
:lighter " compact"
(if compact-docstrings-mode
(font-lock-add-keywords nil compact-docstrings--keywords 'append)
(font-lock-remove-keywords nil compact-docstrings--keywords))
(if (fboundp #'font-lock-flush)
(font-lock-flush)
(with-no-warnings (font-lock-fontify-buffer))))
(defun compact-docstrings--mode-on ()
"Turn on `compact-docstrings-mode', if appropriate."
(when (derived-mode-p major-mode #'prog-mode)
(compact-docstrings-mode)))
;;;###autoload
(defalias 'shrink-docstrings #'compact-docstrings--mode-on)
;;;###autoload
(define-globalized-minor-mode global-compact-docstrings-mode compact-docstrings-mode
compact-docstrings--mode-on
:init-value nil)
(provide 'compact-docstrings)
;;; compact-docstrings.el ends here
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2016-06-20 19:11 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-09 14:57 Paragraph styles in doc strings Lars Ingebrigtsen
2016-05-09 15:01 ` Dmitry Gutov
2016-05-09 15:07 ` Kaushal Modi
2016-05-11 1:52 ` John Wiegley
2016-05-12 20:37 ` Lars Ingebrigtsen
2016-05-16 20:53 ` Stefan Monnier
2016-06-01 23:01 ` Clément Pit--Claudel
2016-06-02 1:18 ` Stefan Monnier
2016-06-20 19:11 ` Clément Pit--Claudel [this message]
2016-06-21 1:18 ` Stefan Monnier
2016-06-21 3:24 ` Clément Pit--Claudel
2016-05-18 6:05 ` John Wiegley
2016-05-09 16:05 ` Drew Adams
2016-05-09 15:10 ` Paul Eggert
2016-05-09 15:48 ` Marcin Borkowski
2016-05-09 16:12 ` Paul Eggert
2016-05-09 15:22 ` Andreas Schwab
2016-05-09 15:42 ` Lars Ingebrigtsen
2016-05-09 15:45 ` Marcin Borkowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=57683FF6.9020100@gmail.com \
--to=clement.pit@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.