-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
114 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
;;; rg-header.el --- Header for rg mode -*- lexical-binding: t; -*- | ||
|
||
;; Copyright (C) 2017 David Landell <david.landell@sunnyhill.email> | ||
;; | ||
;; Author: David Landell <david.landell@sunnyhill.email> | ||
|
||
;; This file is not part of GNU Emacs. | ||
|
||
;; 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, write to the Free Software | ||
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
;; 02110-1301, USA. | ||
|
||
;;; Commentary: | ||
|
||
;;; Code: | ||
|
||
(defcustom rg-show-header t | ||
"Show header in results buffer if non nil." | ||
:type 'boolean | ||
:group 'rg) | ||
|
||
(defface rg-toggle-on-face | ||
'((t :inherit rg-file-tag-face)) | ||
"face for toggle 'on' text in header." | ||
:group 'rg-face) | ||
|
||
(defface rg-toggle-off-face | ||
'((t :inherit rg-error-face)) | ||
"face for toggle 'off' text in header." | ||
:group 'rg-face) | ||
|
||
(defface rg-literal-face | ||
'((t :inherit rg-filename-face)) | ||
"face for literal label in header." | ||
:group 'rg-face) | ||
|
||
(defface rg-regexp-face | ||
'((t :inherit compilation-line-number)) | ||
"face for regexp label in header." | ||
:group 'rg-face) | ||
|
||
(defvar rg-last-search) | ||
|
||
(defun rg-header-render-label (labelform) | ||
"Return a fontified header label. | ||
LABELFORM is either a string to render or a form where the `car' is a | ||
conditional and the two following items are then and else specs. | ||
Specs are lists where the the `car' is the labels string and the | ||
`cadr' is font to use for that string." | ||
(list '(:propertize "[" font-lock-face (header-line bold)) | ||
(cond | ||
((stringp labelform) | ||
`(:propertize ,labelform font-lock-face (header-line bold))) | ||
((listp labelform) | ||
(let* ((condition (nth 0 labelform)) | ||
(then (nth 1 labelform)) | ||
(else (nth 2 labelform))) | ||
`(,condition | ||
(:propertize ,(nth 0 then) font-lock-face (,(nth 1 then) header-line bold)) | ||
(:propertize ,(nth 0 else) font-lock-face (,(nth 1 else) header-line bold))))) | ||
(t (error "Not a string or list"))) | ||
'(:propertize "]" font-lock-face (header-line bold)) | ||
'(": "))) | ||
|
||
(defun rg-header-render-toggle (on) | ||
"Return a fontified toggle symbol. | ||
If ON is non nil, render \"on\" string, otherwise render \"off\" | ||
string." | ||
`(:eval (let* ((on ,on) | ||
(value (if on "on " "off")) | ||
(face (if on 'rg-toggle-on-face 'rg-toggle-off-face))) | ||
(propertize value 'font-lock-face `(bold ,face))))) | ||
|
||
(defun rg-create-header-line () | ||
"Create the header line if `rg-show-header' is enabled." | ||
(when rg-show-header | ||
(let ((itemspace " ")) | ||
(setq header-line-format | ||
(if (null rg-last-search) | ||
(list | ||
(rg-header-render-label "command line") | ||
"no refinement") | ||
(list | ||
(rg-header-render-label '(rg-literal ("literal" rg-literal-face) | ||
("regexp" rg-regexp-face))) | ||
'(:eval (nth 0 rg-last-search)) itemspace | ||
(rg-header-render-label "files") | ||
'(:eval (nth 1 rg-last-search)) itemspace | ||
(rg-header-render-label "case") | ||
(rg-header-render-toggle | ||
'(not (member "-i" rg-toggle-command-line-flags))) itemspace | ||
(rg-header-render-label "ign") | ||
(rg-header-render-toggle | ||
'(not (member "--no-ignore" rg-toggle-command-line-flags))) itemspace | ||
(rg-header-render-label "hits") | ||
'(:eval (format "%d" rg-hit-count)))))))) | ||
|
||
(provide 'rg-header) | ||
|
||
;;; rg-header.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters