Fix some stuff from the last commit
This commit is contained in:
parent
93ed2b9e39
commit
046ba351ce
48
init.el
48
init.el
@ -919,58 +919,54 @@ COMMAND and COMINT are like `compile'."
|
|||||||
(regexp-opt '("gschema" "gresource" "ui")) "\\'") . nxml-mode)))
|
(regexp-opt '("gschema" "gresource" "ui")) "\\'") . nxml-mode)))
|
||||||
|
|
||||||
;; Bibtex (built in)
|
;; Bibtex (built in)
|
||||||
(use-package bibtex
|
(require 'bibtex)
|
||||||
:ensure nil
|
(defun my/bibtex-in-entry-p (&optional exclude-braces)
|
||||||
:defer nil
|
|
||||||
:config
|
|
||||||
(defun my/bibtex-in-entry-p (&optional exclude-braces)
|
|
||||||
"Return t is point is inside a BibTeX entry.
|
"Return t is point is inside a BibTeX entry.
|
||||||
When EXCLUDE-BRACES is non-nil, don't count the first and last brace of the
|
When EXCLUDE-BRACES is non-nil, don't count the first and last brace of the
|
||||||
entry as in the entry. That is, if the point is on the first { or last } of the
|
entry as in the entry. That is, if the point is on the first { or last } of the
|
||||||
entry, return nil."
|
entry, return nil."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
;; go to top level and check if the character at point is {
|
(when (and exclude-braces (= ?\} (char-after)))
|
||||||
(when (and (not exclude-braces) (= ?{ (char-after)))
|
|
||||||
(forward-char))
|
(forward-char))
|
||||||
|
;; go to top level and check if the character at point is {
|
||||||
(let ((start-pos (point))
|
(let ((start-pos (point))
|
||||||
(last-valid (point)))
|
(last-valid (point)))
|
||||||
(condition-case _
|
(condition-case _
|
||||||
(while t
|
(while t
|
||||||
(up-list 1 t t)
|
(backward-up-list 1 t t)
|
||||||
(setq last-valid (point)))
|
(setq last-valid (point)))
|
||||||
(error
|
(error
|
||||||
(and
|
(and
|
||||||
(= ?\} (char-before last-valid))
|
(= ?\{ (char-after last-valid))
|
||||||
;; up-point moves to the char after the last brace, so if the point
|
;; up-point moves to the char after the last brace, so if the point
|
||||||
;; started there, we aren't in the entry
|
;; started there, we aren't in the entry
|
||||||
(not (= start-pos last-valid))
|
|
||||||
(or (not exclude-braces)
|
(or (not exclude-braces)
|
||||||
(not (= start-pos (1- last-valid))))))))))
|
(not (= start-pos last-valid)))))))))
|
||||||
(defvar my/bibtex-indent-width 4
|
(defvar my/bibtex-indent-width 4
|
||||||
"Width to indent for `my/bibtex-calculate-indentation'.")
|
"Width to indent for `my/bibtex-calculate-indentation'.")
|
||||||
(defun my/bibtex-calculate-indentation ()
|
(defun my/bibtex-calculate-indentation ()
|
||||||
"Calculate the column to indent to on the current line."
|
"Calculate the column to indent to on the current line."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(back-to-indentation)
|
(back-to-indentation)
|
||||||
(if (my/bibtex-in-entry-p t)
|
(if (my/bibtex-in-entry-p t)
|
||||||
my/bibtex-indent-width
|
my/bibtex-indent-width
|
||||||
0)))
|
0)))
|
||||||
(defun my/bibtex-empty-line-p ()
|
(defun my/bibtex-empty-line-p ()
|
||||||
"Return t if the current line is only blank characters."
|
"Return t if the current line is only blank characters."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(looking-at (rx (* blank) eol))))
|
(looking-at (rx (* blank) eol))))
|
||||||
(defun my/bibtex-indent-line ()
|
(defun my/bibtex-indent-line ()
|
||||||
"Indent the current line."
|
"Indent the current line."
|
||||||
(interactive)
|
(interactive)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(when (my/bibtex-empty-line-p)
|
(when (looking-at (rx (+ blank)))
|
||||||
(delete-region (point) (match-end 0)))
|
(delete-region (point) (match-end 0)))
|
||||||
(indent-to (my/bibtex-calculate-indentation)))
|
(indent-to (my/bibtex-calculate-indentation)))
|
||||||
(when (looking-at (rx (+ blank) eol))
|
(when (looking-at (rx (+ blank) eol))
|
||||||
(end-of-line)))
|
(end-of-line)))
|
||||||
(defun my/bibtex-indent-or-find-text ()
|
(defun my/bibtex-indent-or-find-text ()
|
||||||
"Either indent the current line or jump to the current fields text.
|
"Either indent the current line or jump to the current fields text.
|
||||||
If the current line is only whitespace call `my/bibtex-calculate-indentation',
|
If the current line is only whitespace call `my/bibtex-calculate-indentation',
|
||||||
otherwise, call `bibtex-find-text'."
|
otherwise, call `bibtex-find-text'."
|
||||||
@ -978,20 +974,22 @@ otherwise, call `bibtex-find-text'."
|
|||||||
(if (my/bibtex-empty-line-p)
|
(if (my/bibtex-empty-line-p)
|
||||||
(my/bibtex-indent-line)
|
(my/bibtex-indent-line)
|
||||||
(bibtex-find-text)))
|
(bibtex-find-text)))
|
||||||
(defun my/bibtex-indent-or-find-text-and-insert ()
|
(defun my/bibtex-indent-or-find-text-and-insert ()
|
||||||
"Like `my/bibtex-indent-or-find-text', but enter insert mode after."
|
"Like `my/bibtex-indent-or-find-text', but enter insert mode after."
|
||||||
(interactive)
|
(interactive)
|
||||||
(my/bibtex-indent-or-find-text)
|
(my/bibtex-indent-or-find-text)
|
||||||
(if (my/bibtex-empty-line-p)
|
(if (my/bibtex-empty-line-p)
|
||||||
(evil-append 1)
|
(evil-append 1)
|
||||||
(evil-insert 1)))
|
(evil-insert 1)))
|
||||||
(defun my/-bibtex-setup-indent ()
|
(defun my/-bibtex-setup-indent ()
|
||||||
(setq-local indent-line-function 'my/bibtex-indent-line))
|
"Set up `bibtex-mode' indentation stuff."
|
||||||
(add-hook 'bibtex-mode-hook 'my/-bibtex-setup-indent)
|
(setq-local indent-line-function 'my/bibtex-indent-line
|
||||||
(define-key bibtex-mode-map (kbd "RET") 'newline-and-indent)
|
electric-indent-chars '(?\n ?\{ ?\} ?,)))
|
||||||
(define-key bibtex-mode-map (kbd "TAB") 'my/bibtex-indent-or-find-text)
|
(add-hook 'bibtex-mode-hook 'my/-bibtex-setup-indent)
|
||||||
(evil-define-key 'normal bibtex-mode-map
|
(define-key bibtex-mode-map (kbd "RET") 'newline-and-indent)
|
||||||
(kbd "TAB") 'my/bibtex-indent-or-find-text-and-insert))
|
(define-key bibtex-mode-map (kbd "TAB") 'my/bibtex-indent-or-find-text)
|
||||||
|
(evil-define-key 'normal bibtex-mode-map
|
||||||
|
(kbd "TAB") 'my/bibtex-indent-or-find-text-and-insert)
|
||||||
|
|
||||||
;; AUCTeX
|
;; AUCTeX
|
||||||
(use-package auctex
|
(use-package auctex
|
||||||
|
Loading…
Reference in New Issue
Block a user