Dataset Viewer
Auto-converted to Parquet
entities
list
max_stars_repo_path
stringlengths
4
142
max_stars_repo_name
stringlengths
7
65
max_stars_count
int64
0
14.7k
content
stringlengths
40
980k
id
stringlengths
1
5
new_content
stringlengths
43
980k
modified
bool
1 class
references
stringlengths
57
980k
[ { "context": "C) 2007 Free Software Foundation, Inc.\n\n;; Author: Ralf Angeli <[email protected]>\n;; Maintainer: auctex-deve", "end": 132, "score": 0.9998667240142822, "start": 121, "tag": "NAME", "value": "Ralf Angeli" }, { "context": "oftware Foundation, Inc.\n\n;; Author: Ralf Angeli <[email protected]>\n;; Maintainer: [email protected]\n;; Created: ", "end": 154, "score": 0.9999372959136963, "start": 134, "tag": "EMAIL", "value": "[email protected]" }, { "context": " Ralf Angeli <[email protected]>\n;; Maintainer: [email protected]\n;; Created: 2007-10-09\n;; Keywords: tex\n\n;; This ", "end": 191, "score": 0.9999245405197144, "start": 171, "tag": "EMAIL", "value": "[email protected]" } ]
elpa/auctex-12.1.0/style/nomencl.el
hckrtst/emacs-config
6
;;; nomencl.el --- AUCTeX style for the nomencl class. ;; Copyright (C) 2007 Free Software Foundation, Inc. ;; Author: Ralf Angeli <[email protected]> ;; Maintainer: [email protected] ;; Created: 2007-10-09 ;; Keywords: tex ;; This file is part of AUCTeX. ;; AUCTeX 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, or (at your option) ;; any later version. ;; AUCTeX 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 AUCTeX; see the file COPYING. If not, write to the Free ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA ;; 02110-1301, USA. ;;; Commentary: ;; This file adds support for the nomencl package. ;;; Code: (defvar LaTeX-nomencl-package-options '("refeq" "norefeq" "refpage" "norefpage" "prefix" "noprefix" "cfg" "nocfg" "intoc" "notintoq" "compatible" "noncompatible" "croatian" "danish" "english" "french" "german" "italian" "polish" "portuguese" "russian" "spanish" "ukrainian") "Package options for the nomencl package.") (TeX-add-style-hook "nomencl" (lambda () (TeX-add-symbols '("makenomenclature" 0) '("printnomenclature" ["Label width"]) '("nomenclature" ["Prefix"] "Symbol" "Description") "nomrefeq" "nomrefpage" "nomrefeqpage" "nomnorefeq" "nomnorefpage" "nomnorefeqpage" '("nomlabelwidth" 0) '("nomname" 0) '("nomgroup" 0) '("nompreamble" 0) '("nompostamble" 0) '("nomitemsep" 0) '("nomprefix" 0) '("nomlabel" 0) '("nomentryend" 0) '("eqdeclaration" 0) '("pagedeclaration" 0)) ;; Fontification (when (and (featurep 'font-latex) (eq TeX-install-font-lock 'font-latex-setup)) (font-latex-add-keywords '(("nomenclature" "[{{")) 'reference))) LaTeX-dialect) ;;; nomencl.el ends here
34619
;;; nomencl.el --- AUCTeX style for the nomencl class. ;; Copyright (C) 2007 Free Software Foundation, Inc. ;; Author: <NAME> <<EMAIL>> ;; Maintainer: <EMAIL> ;; Created: 2007-10-09 ;; Keywords: tex ;; This file is part of AUCTeX. ;; AUCTeX 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, or (at your option) ;; any later version. ;; AUCTeX 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 AUCTeX; see the file COPYING. If not, write to the Free ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA ;; 02110-1301, USA. ;;; Commentary: ;; This file adds support for the nomencl package. ;;; Code: (defvar LaTeX-nomencl-package-options '("refeq" "norefeq" "refpage" "norefpage" "prefix" "noprefix" "cfg" "nocfg" "intoc" "notintoq" "compatible" "noncompatible" "croatian" "danish" "english" "french" "german" "italian" "polish" "portuguese" "russian" "spanish" "ukrainian") "Package options for the nomencl package.") (TeX-add-style-hook "nomencl" (lambda () (TeX-add-symbols '("makenomenclature" 0) '("printnomenclature" ["Label width"]) '("nomenclature" ["Prefix"] "Symbol" "Description") "nomrefeq" "nomrefpage" "nomrefeqpage" "nomnorefeq" "nomnorefpage" "nomnorefeqpage" '("nomlabelwidth" 0) '("nomname" 0) '("nomgroup" 0) '("nompreamble" 0) '("nompostamble" 0) '("nomitemsep" 0) '("nomprefix" 0) '("nomlabel" 0) '("nomentryend" 0) '("eqdeclaration" 0) '("pagedeclaration" 0)) ;; Fontification (when (and (featurep 'font-latex) (eq TeX-install-font-lock 'font-latex-setup)) (font-latex-add-keywords '(("nomenclature" "[{{")) 'reference))) LaTeX-dialect) ;;; nomencl.el ends here
true
;;; nomencl.el --- AUCTeX style for the nomencl class. ;; Copyright (C) 2007 Free Software Foundation, Inc. ;; Author: PI:NAME:<NAME>END_PI <PI:EMAIL:<EMAIL>END_PI> ;; Maintainer: PI:EMAIL:<EMAIL>END_PI ;; Created: 2007-10-09 ;; Keywords: tex ;; This file is part of AUCTeX. ;; AUCTeX 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, or (at your option) ;; any later version. ;; AUCTeX 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 AUCTeX; see the file COPYING. If not, write to the Free ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA ;; 02110-1301, USA. ;;; Commentary: ;; This file adds support for the nomencl package. ;;; Code: (defvar LaTeX-nomencl-package-options '("refeq" "norefeq" "refpage" "norefpage" "prefix" "noprefix" "cfg" "nocfg" "intoc" "notintoq" "compatible" "noncompatible" "croatian" "danish" "english" "french" "german" "italian" "polish" "portuguese" "russian" "spanish" "ukrainian") "Package options for the nomencl package.") (TeX-add-style-hook "nomencl" (lambda () (TeX-add-symbols '("makenomenclature" 0) '("printnomenclature" ["Label width"]) '("nomenclature" ["Prefix"] "Symbol" "Description") "nomrefeq" "nomrefpage" "nomrefeqpage" "nomnorefeq" "nomnorefpage" "nomnorefeqpage" '("nomlabelwidth" 0) '("nomname" 0) '("nomgroup" 0) '("nompreamble" 0) '("nompostamble" 0) '("nomitemsep" 0) '("nomprefix" 0) '("nomlabel" 0) '("nomentryend" 0) '("eqdeclaration" 0) '("pagedeclaration" 0)) ;; Fontification (when (and (featurep 'font-latex) (eq TeX-install-font-lock 'font-latex-setup)) (font-latex-add-keywords '(("nomenclature" "[{{")) 'reference))) LaTeX-dialect) ;;; nomencl.el ends here
[ { "context": "cal-binding: t; -*-\n\n;; Copyright (C) 2013-2015 by Artem Malyshev\n\n;; Author: Artem Malyshev <[email protected]>", "end": 163, "score": 0.999871551990509, "start": 149, "tag": "NAME", "value": "Artem Malyshev" }, { "context": "yright (C) 2013-2015 by Artem Malyshev\n\n;; Author: Artem Malyshev <[email protected]>\n;; URL: https://github.com", "end": 190, "score": 0.999889075756073, "start": 176, "tag": "NAME", "value": "Artem Malyshev" }, { "context": "015 by Artem Malyshev\n\n;; Author: Artem Malyshev <[email protected]>\n;; URL: https://github.com/proofit404/anaconda-m", "end": 212, "score": 0.9999027252197266, "start": 192, "tag": "EMAIL", "value": "[email protected]" }, { "context": "<[email protected]>\n;; URL: https://github.com/proofit404/anaconda-mode\n;; Package-Version: 20150922.537\n;;", "end": 251, "score": 0.9922154545783997, "start": 241, "tag": "USERNAME", "value": "proofit404" }, { "context": ";; Server.\n\n(defvar anaconda-mode-server-version \"0.1.1\"\n \"Server version needed to run anaconda-mode.\")", "end": 3008, "score": 0.9985655546188354, "start": 3003, "tag": "IP_ADDRESS", "value": "0.1.1" }, { "context": "e-name\n (pythonic-tramp-connection)))\n \"127.0.0.1\"))\n\n(defun anaconda-mode-start (&optional callbac", "end": 4705, "score": 0.9997422695159912, "start": 4696, "tag": "IP_ADDRESS", "value": "127.0.0.1" } ]
.emacs.d/elpa/anaconda-mode-20150922.537/anaconda-mode.el
mikhsol/emacs-config
1
;;; anaconda-mode.el --- Code navigation, documentation lookup and completion for Python -*- lexical-binding: t; -*- ;; Copyright (C) 2013-2015 by Artem Malyshev ;; Author: Artem Malyshev <[email protected]> ;; URL: https://github.com/proofit404/anaconda-mode ;; Package-Version: 20150922.537 ;; Version: 0.1.1 ;; Package-Requires: ((emacs "24") (pythonic "0.1.0") (dash "2.6.0") (s "1.9") (f "0.16.2")) ;; 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: ;; See the README for more details. ;;; Code: (eval-when-compile (defvar url-http-end-of-headers)) (require 'tramp) (require 'url) (require 'json) (require 'pythonic) (require 'dash) (require 's) (require 'f) (defgroup anaconda-mode nil "Code navigation, documentation lookup and completion for Python." :group 'programming) (defcustom anaconda-mode-installation-directory "~/.emacs.d/anaconda-mode" "Installation directory for anaconda-mode server." :group 'anaconda-mode :type 'directory) (defcustom anaconda-mode-complete-callback 'anaconda-mode-complete-callback "Callback function used to display `anaconda-mode-complete' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-show-doc-callback 'anaconda-mode-show-doc-callback "Callback function used to display `anaconda-mode-show-doc' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-find-definitions-callback 'anaconda-mode-find-definitions-callback "Callback function used to display `anaconda-mode-find-definitions' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-find-assignments-callback 'anaconda-mode-find-assignments-callback "Callback function used to display `anaconda-mode-find-assignments' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-find-references-callback 'anaconda-mode-find-references-callback "Callback function used to display `anaconda-mode-find-references' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-eldoc-callback 'anaconda-mode-eldoc-callback "Callback function used to display `anaconda-mode-eldoc-function' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-eldoc-as-single-line nil "If not nil, trim eldoc string to frame width." :group 'anaconda-mode :type 'boolean) ;;; Server. (defvar anaconda-mode-server-version "0.1.1" "Server version needed to run anaconda-mode.") (defvar anaconda-mode-server-script "anaconda_mode.py" "Script file with anaconda-mode server.") (defvar anaconda-mode-process-name "anaconda-mode" "Process name for anaconda-mode processes.") (defvar anaconda-mode-process-buffer "*anaconda-mode*" "Buffer name for anaconda-mode processes.") (defvar anaconda-mode-process nil "Currently running anaconda-mode process.") (defvar anaconda-mode-port nil "Port for anaconda-mode connection.") (defvar anaconda-mode-ensure-directory-command " import os import sys directory = sys.argv[-1] if not os.path.exists(directory): os.makedirs(directory) " "Create `anaconda-mode-server-directory' if necessary.") (defvar anaconda-mode-check-installation-command " import sys, os from pkg_resources import find_distributions directory = sys.argv[-1] for dist in find_distributions(directory, only=True): if dist.project_name == 'anaconda-mode': break else: # IPython patch sys.exit, so we can't use it. os._exit(1) " "Check if `anaconda-mode' server is installed or not.") (defvar anaconda-mode-install-server-command " import sys import pip directory = sys.argv[-2] version = sys.argv[-1] pip.main(['install', '-t', directory, 'anaconda_mode==' + version]) " "Install `anaconda_mode' server.") (defun anaconda-mode-server-directory () "Anaconda mode installation directory." (f-join anaconda-mode-installation-directory anaconda-mode-server-version)) (defun anaconda-mode-host () "Target host with anaconda-mode server." (if (pythonic-remote-p) (tramp-file-name-host (tramp-dissect-file-name (pythonic-tramp-connection))) "127.0.0.1")) (defun anaconda-mode-start (&optional callback) "Start anaconda-mode server. CALLBACK function will be called when `anaconda-mode-port' will be bound." (when (anaconda-mode-need-restart) (anaconda-mode-stop)) (if (anaconda-mode-running-p) (when callback (funcall callback)) (anaconda-mode-ensure-directory callback))) (defun anaconda-mode-stop () "Stop anaconda-mode server." (when (anaconda-mode-running-p) (set-process-filter anaconda-mode-process nil) (set-process-sentinel anaconda-mode-process nil) (kill-process anaconda-mode-process) (setq anaconda-mode-process nil anaconda-mode-port nil))) (defun anaconda-mode-running-p () "Is `anaconda-mode' server running." (and anaconda-mode-process (process-live-p anaconda-mode-process))) (defun anaconda-mode-bound-p () "Is `anaconda-mode' port bound." (numberp anaconda-mode-port)) (defun anaconda-mode-need-restart () "Check if we need to restart `anaconda-mode-server'." (when (and (anaconda-mode-running-p) (anaconda-mode-bound-p)) (or (not (pythonic-proper-environment-p anaconda-mode-process)) (not (equal (process-get anaconda-mode-process 'server-directory) (anaconda-mode-server-directory)))))) (defun anaconda-mode-ensure-directory (&optional callback) "Ensure if `anaconda-mode-server-directory' exists. CALLBACK function will be called when `anaconda-mode-port' will be bound." (setq anaconda-mode-process (start-pythonic :process anaconda-mode-process-name :buffer anaconda-mode-process-buffer :sentinel (lambda (process event) (anaconda-mode-ensure-directory-sentinel process event callback)) :args (list "-c" anaconda-mode-ensure-directory-command (anaconda-mode-server-directory))))) (defun anaconda-mode-ensure-directory-sentinel (process _event &optional callback) "Run `anaconda-mode-check' if `anaconda-mode-server-directory' exists. Raise error otherwise. PROCESS and EVENT are basic sentinel parameters. CALLBACK function will be called when `anaconda-mode-port' will be bound." (if (eq 0 (process-exit-status process)) (anaconda-mode-check callback) (pop-to-buffer anaconda-mode-process-buffer) (error "Can't create %s directory" (anaconda-mode-server-directory)))) (defun anaconda-mode-check (&optional callback) "Check `anaconda-mode' server installation. CALLBACK function will be called when `anaconda-mode-port' will be bound." (setq anaconda-mode-process (start-pythonic :process anaconda-mode-process-name :buffer anaconda-mode-process-buffer :sentinel (lambda (process event) (anaconda-mode-check-sentinel process event callback)) :args (list "-c" anaconda-mode-check-installation-command (anaconda-mode-server-directory))))) (defun anaconda-mode-check-sentinel (process _event &optional callback) "Run `anaconda-mode-bootstrap' if server installation check passed. Try to install `anaconda-mode' server otherwise. PROCESS and EVENT are basic sentinel parameters. CALLBACK function will be called when `anaconda-mode-port' will be bound." (if (eq 0 (process-exit-status process)) (anaconda-mode-bootstrap callback) (anaconda-mode-install callback))) (defun anaconda-mode-install (&optional callback) "Try to install `anaconda-mode' server. CALLBACK function will be called when `anaconda-mode-port' will be bound." (setq anaconda-mode-process (start-pythonic :process anaconda-mode-process-name :buffer anaconda-mode-process-buffer :sentinel (lambda (process event) (anaconda-mode-install-sentinel process event callback)) :args (list "-c" anaconda-mode-install-server-command (anaconda-mode-server-directory) anaconda-mode-server-version)))) (defun anaconda-mode-install-sentinel (process _event &optional callback) "Run `anaconda-mode-bootstrap' if server installation complete successfully. Raise error otherwise. PROCESS and EVENT are basic sentinel parameters. CALLBACK function will be called when `anaconda-mode-port' will be bound." (if (eq 0 (process-exit-status process)) (anaconda-mode-bootstrap callback) (pop-to-buffer anaconda-mode-process-buffer) (error "Can't install `anaconda-mode' server"))) (defun anaconda-mode-bootstrap (&optional callback) "Run `anaconda-mode' server. CALLBACK function will be called when `anaconda-mode-port' will be bound." (setq anaconda-mode-process (start-pythonic :process anaconda-mode-process-name :buffer anaconda-mode-process-buffer :cwd (anaconda-mode-server-directory) :filter (lambda (process output) (anaconda-mode-bootstrap-filter process output callback)) :sentinel 'anaconda-mode-bootstrap-sentinel :query-on-exit nil :args (list anaconda-mode-server-script))) (process-put anaconda-mode-process 'server-directory (anaconda-mode-server-directory))) (defun anaconda-mode-bootstrap-filter (process output &optional callback) "Set `anaconda-mode-port' from PROCESS OUTPUT. Connect to the `anaconda-mode' server. CALLBACK function will be called when `anaconda-mode-port' will be bound." ;; Mimic default filter. (when (buffer-live-p (process-buffer process)) (with-current-buffer (process-buffer process) (save-excursion (goto-char (process-mark process)) (insert output) (set-marker (process-mark process) (point))))) (--when-let (s-match "anaconda_mode port \\([0-9]+\\)" output) (setq anaconda-mode-port (string-to-number (cadr it))) (set-process-filter process nil) (when callback (funcall callback)))) (defun anaconda-mode-bootstrap-sentinel (process _event) "Raise error if `anaconda-mode' server exit abnormally. PROCESS and EVENT are basic sentinel parameters." (unless (eq 0 (process-exit-status process)) (pop-to-buffer anaconda-mode-process-buffer) (error "Can't start `anaconda-mode' server"))) ;;; Interaction. (defun anaconda-mode-call (command callback) "Make remote procedure call for COMMAND. Apply CALLBACK to it result." (anaconda-mode-start (lambda () (anaconda-mode-jsonrpc command callback)))) (defun anaconda-mode-jsonrpc (command callback) "Perform JSONRPC call for COMMAND. Apply CALLBACK to the call result when retrieve it. Remote COMMAND must expect four arguments: python buffer content, line number position, column number position and file path." (let ((url-request-method "POST") (url-request-data (anaconda-mode-jsonrpc-request command))) (url-retrieve (format "http://%s:%s" (anaconda-mode-host) anaconda-mode-port) (anaconda-mode-create-response-handler command callback) nil t))) (defun anaconda-mode-jsonrpc-request (command) "Prepare JSON encoded buffer data for COMMAND call." (json-encode (anaconda-mode-jsonrpc-request-data command))) (defun anaconda-mode-jsonrpc-request-data (command) "Prepare buffer data for COMMAND call." `((jsonrpc . "2.0") (id . 1) (method . ,command) (params . ((source . ,(buffer-substring-no-properties (point-min) (point-max))) (line . ,(line-number-at-pos (point))) (column . ,(- (point) (line-beginning-position))) (path . ,(when (buffer-file-name) (pythonic-file-name (buffer-file-name)))))))) (defun anaconda-mode-create-response-handler (command callback) "Create server response handler based on COMMAND and CALLBACK function. COMMAND argument will be used for response skip message. Response can be skipped if point was moved sense request was submitted." (let ((anaconda-mode-request-point (point)) (anaconda-mode-request-buffer (current-buffer)) (anaconda-mode-request-window (selected-window)) (anaconda-mode-request-tick (buffer-chars-modified-tick))) (lambda (_status) (let ((http-buffer (current-buffer))) (unwind-protect (if (or (not (equal anaconda-mode-request-window (selected-window))) (with-current-buffer (window-buffer anaconda-mode-request-window) (or (not (equal anaconda-mode-request-buffer (current-buffer))) (not (equal anaconda-mode-request-point (point))) (not (equal anaconda-mode-request-tick (buffer-chars-modified-tick)))))) (message "Skip anaconda-mode %s response" command) (goto-char url-http-end-of-headers) (let* ((json-array-type 'list) (response (condition-case nil (json-read) (json-readtable-error (progn (let ((response-string (buffer-string))) (pop-to-buffer (with-current-buffer (get-buffer-create "*anaconda-response*") (insert response-string) (goto-char (point-min)) (current-buffer)))) (error "Can't read anaconda-mode server response")))))) (if (assoc 'error response) (error (cdr (assoc 'error response))) (with-current-buffer anaconda-mode-request-buffer ;; Terminate `apply' call with empty list so response ;; will be treated as single argument. (apply callback (cdr (assoc 'result response)) nil))))) (kill-buffer http-buffer)))))) ;;; Code completion. (defun anaconda-mode-complete () "Request completion candidates." (interactive) (unless (python-syntax-comment-or-string-p) (anaconda-mode-call "complete" anaconda-mode-complete-callback))) (defun anaconda-mode-complete-callback (result) "Start interactive completion on RESULT receiving." (let* ((bounds (bounds-of-thing-at-point 'symbol)) (start (or (car bounds) (point))) (stop (or (cdr bounds) (point))) (collection (anaconda-mode-complete-extract-names result)) (completion-extra-properties '(:annotation-function anaconda-mode-complete-annotation))) (completion-in-region start stop collection))) (defun anaconda-mode-complete-extract-names (result) "Extract completion names from anaconda-mode RESULT." (--map (let* ((name (cdr (assoc 'name it))) (type (cdr (assoc 'type it))) (module-path (cdr (assoc 'module-path it))) (line (cdr (assoc 'line it))) (docstring (cdr (assoc 'docstring it))) (description (if (equal type "statement") "statement" (cdr (assoc 'description it))))) (put-text-property 0 1 'description description name) (put-text-property 0 1 'module-path module-path name) (put-text-property 0 1 'line line name) (put-text-property 0 1 'docstring docstring name) name) result)) (defun anaconda-mode-complete-annotation (candidate) "Get annotation for CANDIDATE." (--when-let (get-text-property 0 'description candidate) (concat " <" it ">"))) ;;; View documentation. (defun anaconda-mode-show-doc () "Show documentation for context at point." (interactive) (anaconda-mode-call "goto_definitions" anaconda-mode-show-doc-callback)) (defun anaconda-mode-show-doc-callback (result) "Process view doc RESULT." (if result (anaconda-mode-documentation-view result) (message "No documentation available"))) ;;; Find definitions. (defun anaconda-mode-find-definitions () "Find definitions for thing at point." (interactive) (anaconda-mode-call "goto_definitions" anaconda-mode-find-definitions-callback)) (defun anaconda-mode-find-definitions-callback (result) "Process find definitions RESULT." (if result (anaconda-mode-definitions-view result) (message "No definitions found"))) ;;; Find assignments. (defun anaconda-mode-find-assignments () "Find assignments for thing at point." (interactive) (anaconda-mode-call "goto_assignments" anaconda-mode-find-assignments-callback)) (defun anaconda-mode-find-assignments-callback (result) "Process find assignments RESULT." (if result (anaconda-mode-definitions-view result) (message "No assignments found"))) ;;; Find references. (defun anaconda-mode-find-references () "Find references for thing at point." (interactive) (anaconda-mode-call "usages" anaconda-mode-find-references-callback)) (defun anaconda-mode-find-references-callback (result) "Process find references RESULT." (if result (anaconda-mode-definitions-view result) (message "No references found"))) ;;; Eldoc. (defun anaconda-mode-eldoc-function () "Show eldoc for context at point." (anaconda-mode-call "eldoc" anaconda-mode-eldoc-callback)) (defun anaconda-mode-eldoc-callback (result) "Display eldoc from server RESULT." (eldoc-message (anaconda-mode-eldoc-format result))) (defun anaconda-mode-eldoc-format (result) "Format eldoc string from RESULT." (when result (let* ((name (cdr (assoc 'name result))) (index (or (cdr (assoc 'index result)) 0)) (params (cdr (assoc 'params result))) (doc (anaconda-mode-eldoc-format-definition name index params))) (if anaconda-mode-eldoc-as-single-line (substring doc 0 (min (frame-width) (length doc))) doc)))) (defun anaconda-mode-eldoc-format-definition (name index params) "Format function definition from NAME, INDEX and PARAMS." (concat (propertize name 'face 'font-lock-function-name-face) "(" (anaconda-mode-eldoc-format-params params index) ")")) (defun anaconda-mode-eldoc-format-params (args index) "Build colorized ARGS string with current arg pointed to INDEX." (->> args (--map-indexed (if (= index it-index) (propertize it 'face 'eldoc-highlight-function-argument) it)) (-interpose ", ") (apply 'concat))) ;;; Result view. (defmacro anaconda-mode-with-view-buffer (&rest body) "Create view buffer and execute BODY in it." `(let ((buf (get-buffer-create "*Anaconda*"))) (with-current-buffer buf (setq buffer-read-only nil) (erase-buffer) ,@body (goto-char (point-min)) (anaconda-mode-view-mode) buf))) (defun anaconda-mode-definitions-view (result) "Show definitions view for rpc RESULT." (if (eq 1 (length result)) (anaconda-mode-find-file (car result)) (anaconda-mode-view result 'anaconda-mode-view-definitions-presenter))) (defun anaconda-mode-documentation-view (result) "Show documentation view for rpc RESULT." (anaconda-mode-view result 'anaconda-mode-view-documentation-presenter)) (defun anaconda-mode-view (result presenter) "Show RESULT to user for future selection. RESULT must be an RESULT field from json-rpc response. PRESENTER is the function used to format buffer content." (pop-to-buffer (anaconda-mode-with-view-buffer (funcall presenter result)))) (defun anaconda-mode-view-make-bold (string) "Make passed STRING look bold." (propertize string 'face 'bold)) (defun anaconda-mode-view-make-source (string) "Make passed STRING look like python source." (with-temp-buffer (insert string) (let ((delay-mode-hooks t)) (python-mode)) (run-hooks 'font-lock-mode-hook) (font-lock-fontify-buffer) (buffer-string))) (define-button-type 'anaconda-mode-definition-button 'action #'anaconda-mode-view-jump 'face nil) (defun anaconda-mode-view-jump (button) "Jump to definition file saved in BUTTON." (let ((definition (button-get button 'definition))) (anaconda-mode-find-file definition))) (defun anaconda-mode-view-jump-other-window (button) "Jump to definition file saved in BUTTON." (let ((definition (button-get button 'definition))) (anaconda-mode-find-file-other-window definition))) (defun anaconda-mode-find-file (definition) "Find DEFINITION file, go to DEFINITION point." (anaconda-mode-find-file-generic definition 'find-file)) (defun anaconda-mode-find-file-other-window (definition) "Find DEFINITION file other window, go to DEFINITION point." (anaconda-mode-find-file-generic definition 'find-file-other-window)) (defvar-local anaconda-mode-go-back-definition nil "Previous definition from which current buffer was navigated.") (defun anaconda-mode-find-file-generic (definition find-function) "Find DEFINITION with FIND-FUNCTION." (let ((backward-navigation (when (buffer-file-name) `((module-path . ,(buffer-file-name)) (line . ,(line-number-at-pos (point))) (column . ,(- (point) (line-beginning-position))))))) (--if-let (cdr (assoc 'module-path definition)) (progn (funcall find-function it) (goto-char 0) (forward-line (1- (cdr (assoc 'line definition)))) (forward-char (cdr (assoc 'column definition))) (setq anaconda-mode-go-back-definition backward-navigation)) (message "Can't open %s module" (cdr (assoc 'module-name definition)))))) (defun anaconda-mode-view-insert-button (name definition) "Insert text button with NAME opening the DEFINITION." (insert-text-button name 'type 'anaconda-mode-definition-button 'definition definition)) (defun anaconda-mode-view-definitions-presenter (result) "Insert definitions from RESULT." (->> (--group-by (cdr (assoc 'module-name it)) result) (--map (anaconda-mode-view-insert-module-definition it)))) (defun anaconda-mode-view-insert-module-definition (module) "Insert MODULE definition into current buffer." (insert (concat (anaconda-mode-view-make-bold (car module)) "\n")) (--map (progn (insert " ") (anaconda-mode-view-insert-button (anaconda-mode-view-make-source (cdr (assoc 'description it))) it) (insert "\n")) (cdr module))) (defun anaconda-mode-view-documentation-presenter (result) "Insert documentation from RESULT." (--map (progn (insert (anaconda-mode-view-make-bold (cdr (assoc 'module-name it)))) (insert "\n") (insert (s-trim-right (cdr (assoc 'docstring it)))) (insert "\n\n")) result)) (defvar anaconda-mode-view-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "n") 'next-error-no-select) (define-key map (kbd "p") 'previous-error-no-select) (define-key map (kbd "q") 'quit-window) map)) (define-derived-mode anaconda-mode-view-mode special-mode "Anaconda-View" "Major mode for definitions view and navigation for `anaconda-mode'. \\{anaconda-mode-view-mode-map}" (setq next-error-function #'anaconda-mode-next-definition)) (defun anaconda-mode-next-definition (num _reset) "Navigate tot the next definition in the view buffer. NUM is the number of definitions to move forward. RESET mean go to the beginning of buffer before definitions navigation." (forward-button num) (anaconda-mode-view-jump-other-window (button-at (point)))) (defun anaconda-mode-go-back () "Jump backward if buffer was navigated from `anaconda-mode' command." (interactive) (if anaconda-mode-go-back-definition (anaconda-mode-find-file anaconda-mode-go-back-definition) (error "No previous buffer"))) ;;; Anaconda minor mode. (defvar anaconda-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "C-M-i") 'anaconda-mode-complete) (define-key map (kbd "M-.") 'anaconda-mode-find-definitions) (define-key map (kbd "M-,") 'anaconda-mode-find-assignments) (define-key map (kbd "M-r") 'anaconda-mode-find-references) (define-key map (kbd "M-*") 'anaconda-mode-go-back) (define-key map (kbd "M-?") 'anaconda-mode-show-doc) map) "Keymap for `anaconda-mode'.") ;;;###autoload (define-minor-mode anaconda-mode "Code navigation, documentation lookup and completion for Python. \\{anaconda-mode-map}" :lighter " Anaconda" :keymap anaconda-mode-map (if anaconda-mode (turn-on-anaconda-mode) (turn-off-anaconda-mode))) (defun turn-on-anaconda-mode () "Turn on `anaconda-mode'." (make-local-variable 'eldoc-documentation-function) (setq-local eldoc-documentation-function 'anaconda-mode-eldoc-function)) (defun turn-off-anaconda-mode () "Turn off `anaconda-mode'." (kill-local-variable 'eldoc-documentation-function)) (provide 'anaconda-mode) ;;; anaconda-mode.el ends here
37761
;;; anaconda-mode.el --- Code navigation, documentation lookup and completion for Python -*- lexical-binding: t; -*- ;; Copyright (C) 2013-2015 by <NAME> ;; Author: <NAME> <<EMAIL>> ;; URL: https://github.com/proofit404/anaconda-mode ;; Package-Version: 20150922.537 ;; Version: 0.1.1 ;; Package-Requires: ((emacs "24") (pythonic "0.1.0") (dash "2.6.0") (s "1.9") (f "0.16.2")) ;; 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: ;; See the README for more details. ;;; Code: (eval-when-compile (defvar url-http-end-of-headers)) (require 'tramp) (require 'url) (require 'json) (require 'pythonic) (require 'dash) (require 's) (require 'f) (defgroup anaconda-mode nil "Code navigation, documentation lookup and completion for Python." :group 'programming) (defcustom anaconda-mode-installation-directory "~/.emacs.d/anaconda-mode" "Installation directory for anaconda-mode server." :group 'anaconda-mode :type 'directory) (defcustom anaconda-mode-complete-callback 'anaconda-mode-complete-callback "Callback function used to display `anaconda-mode-complete' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-show-doc-callback 'anaconda-mode-show-doc-callback "Callback function used to display `anaconda-mode-show-doc' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-find-definitions-callback 'anaconda-mode-find-definitions-callback "Callback function used to display `anaconda-mode-find-definitions' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-find-assignments-callback 'anaconda-mode-find-assignments-callback "Callback function used to display `anaconda-mode-find-assignments' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-find-references-callback 'anaconda-mode-find-references-callback "Callback function used to display `anaconda-mode-find-references' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-eldoc-callback 'anaconda-mode-eldoc-callback "Callback function used to display `anaconda-mode-eldoc-function' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-eldoc-as-single-line nil "If not nil, trim eldoc string to frame width." :group 'anaconda-mode :type 'boolean) ;;; Server. (defvar anaconda-mode-server-version "0.1.1" "Server version needed to run anaconda-mode.") (defvar anaconda-mode-server-script "anaconda_mode.py" "Script file with anaconda-mode server.") (defvar anaconda-mode-process-name "anaconda-mode" "Process name for anaconda-mode processes.") (defvar anaconda-mode-process-buffer "*anaconda-mode*" "Buffer name for anaconda-mode processes.") (defvar anaconda-mode-process nil "Currently running anaconda-mode process.") (defvar anaconda-mode-port nil "Port for anaconda-mode connection.") (defvar anaconda-mode-ensure-directory-command " import os import sys directory = sys.argv[-1] if not os.path.exists(directory): os.makedirs(directory) " "Create `anaconda-mode-server-directory' if necessary.") (defvar anaconda-mode-check-installation-command " import sys, os from pkg_resources import find_distributions directory = sys.argv[-1] for dist in find_distributions(directory, only=True): if dist.project_name == 'anaconda-mode': break else: # IPython patch sys.exit, so we can't use it. os._exit(1) " "Check if `anaconda-mode' server is installed or not.") (defvar anaconda-mode-install-server-command " import sys import pip directory = sys.argv[-2] version = sys.argv[-1] pip.main(['install', '-t', directory, 'anaconda_mode==' + version]) " "Install `anaconda_mode' server.") (defun anaconda-mode-server-directory () "Anaconda mode installation directory." (f-join anaconda-mode-installation-directory anaconda-mode-server-version)) (defun anaconda-mode-host () "Target host with anaconda-mode server." (if (pythonic-remote-p) (tramp-file-name-host (tramp-dissect-file-name (pythonic-tramp-connection))) "127.0.0.1")) (defun anaconda-mode-start (&optional callback) "Start anaconda-mode server. CALLBACK function will be called when `anaconda-mode-port' will be bound." (when (anaconda-mode-need-restart) (anaconda-mode-stop)) (if (anaconda-mode-running-p) (when callback (funcall callback)) (anaconda-mode-ensure-directory callback))) (defun anaconda-mode-stop () "Stop anaconda-mode server." (when (anaconda-mode-running-p) (set-process-filter anaconda-mode-process nil) (set-process-sentinel anaconda-mode-process nil) (kill-process anaconda-mode-process) (setq anaconda-mode-process nil anaconda-mode-port nil))) (defun anaconda-mode-running-p () "Is `anaconda-mode' server running." (and anaconda-mode-process (process-live-p anaconda-mode-process))) (defun anaconda-mode-bound-p () "Is `anaconda-mode' port bound." (numberp anaconda-mode-port)) (defun anaconda-mode-need-restart () "Check if we need to restart `anaconda-mode-server'." (when (and (anaconda-mode-running-p) (anaconda-mode-bound-p)) (or (not (pythonic-proper-environment-p anaconda-mode-process)) (not (equal (process-get anaconda-mode-process 'server-directory) (anaconda-mode-server-directory)))))) (defun anaconda-mode-ensure-directory (&optional callback) "Ensure if `anaconda-mode-server-directory' exists. CALLBACK function will be called when `anaconda-mode-port' will be bound." (setq anaconda-mode-process (start-pythonic :process anaconda-mode-process-name :buffer anaconda-mode-process-buffer :sentinel (lambda (process event) (anaconda-mode-ensure-directory-sentinel process event callback)) :args (list "-c" anaconda-mode-ensure-directory-command (anaconda-mode-server-directory))))) (defun anaconda-mode-ensure-directory-sentinel (process _event &optional callback) "Run `anaconda-mode-check' if `anaconda-mode-server-directory' exists. Raise error otherwise. PROCESS and EVENT are basic sentinel parameters. CALLBACK function will be called when `anaconda-mode-port' will be bound." (if (eq 0 (process-exit-status process)) (anaconda-mode-check callback) (pop-to-buffer anaconda-mode-process-buffer) (error "Can't create %s directory" (anaconda-mode-server-directory)))) (defun anaconda-mode-check (&optional callback) "Check `anaconda-mode' server installation. CALLBACK function will be called when `anaconda-mode-port' will be bound." (setq anaconda-mode-process (start-pythonic :process anaconda-mode-process-name :buffer anaconda-mode-process-buffer :sentinel (lambda (process event) (anaconda-mode-check-sentinel process event callback)) :args (list "-c" anaconda-mode-check-installation-command (anaconda-mode-server-directory))))) (defun anaconda-mode-check-sentinel (process _event &optional callback) "Run `anaconda-mode-bootstrap' if server installation check passed. Try to install `anaconda-mode' server otherwise. PROCESS and EVENT are basic sentinel parameters. CALLBACK function will be called when `anaconda-mode-port' will be bound." (if (eq 0 (process-exit-status process)) (anaconda-mode-bootstrap callback) (anaconda-mode-install callback))) (defun anaconda-mode-install (&optional callback) "Try to install `anaconda-mode' server. CALLBACK function will be called when `anaconda-mode-port' will be bound." (setq anaconda-mode-process (start-pythonic :process anaconda-mode-process-name :buffer anaconda-mode-process-buffer :sentinel (lambda (process event) (anaconda-mode-install-sentinel process event callback)) :args (list "-c" anaconda-mode-install-server-command (anaconda-mode-server-directory) anaconda-mode-server-version)))) (defun anaconda-mode-install-sentinel (process _event &optional callback) "Run `anaconda-mode-bootstrap' if server installation complete successfully. Raise error otherwise. PROCESS and EVENT are basic sentinel parameters. CALLBACK function will be called when `anaconda-mode-port' will be bound." (if (eq 0 (process-exit-status process)) (anaconda-mode-bootstrap callback) (pop-to-buffer anaconda-mode-process-buffer) (error "Can't install `anaconda-mode' server"))) (defun anaconda-mode-bootstrap (&optional callback) "Run `anaconda-mode' server. CALLBACK function will be called when `anaconda-mode-port' will be bound." (setq anaconda-mode-process (start-pythonic :process anaconda-mode-process-name :buffer anaconda-mode-process-buffer :cwd (anaconda-mode-server-directory) :filter (lambda (process output) (anaconda-mode-bootstrap-filter process output callback)) :sentinel 'anaconda-mode-bootstrap-sentinel :query-on-exit nil :args (list anaconda-mode-server-script))) (process-put anaconda-mode-process 'server-directory (anaconda-mode-server-directory))) (defun anaconda-mode-bootstrap-filter (process output &optional callback) "Set `anaconda-mode-port' from PROCESS OUTPUT. Connect to the `anaconda-mode' server. CALLBACK function will be called when `anaconda-mode-port' will be bound." ;; Mimic default filter. (when (buffer-live-p (process-buffer process)) (with-current-buffer (process-buffer process) (save-excursion (goto-char (process-mark process)) (insert output) (set-marker (process-mark process) (point))))) (--when-let (s-match "anaconda_mode port \\([0-9]+\\)" output) (setq anaconda-mode-port (string-to-number (cadr it))) (set-process-filter process nil) (when callback (funcall callback)))) (defun anaconda-mode-bootstrap-sentinel (process _event) "Raise error if `anaconda-mode' server exit abnormally. PROCESS and EVENT are basic sentinel parameters." (unless (eq 0 (process-exit-status process)) (pop-to-buffer anaconda-mode-process-buffer) (error "Can't start `anaconda-mode' server"))) ;;; Interaction. (defun anaconda-mode-call (command callback) "Make remote procedure call for COMMAND. Apply CALLBACK to it result." (anaconda-mode-start (lambda () (anaconda-mode-jsonrpc command callback)))) (defun anaconda-mode-jsonrpc (command callback) "Perform JSONRPC call for COMMAND. Apply CALLBACK to the call result when retrieve it. Remote COMMAND must expect four arguments: python buffer content, line number position, column number position and file path." (let ((url-request-method "POST") (url-request-data (anaconda-mode-jsonrpc-request command))) (url-retrieve (format "http://%s:%s" (anaconda-mode-host) anaconda-mode-port) (anaconda-mode-create-response-handler command callback) nil t))) (defun anaconda-mode-jsonrpc-request (command) "Prepare JSON encoded buffer data for COMMAND call." (json-encode (anaconda-mode-jsonrpc-request-data command))) (defun anaconda-mode-jsonrpc-request-data (command) "Prepare buffer data for COMMAND call." `((jsonrpc . "2.0") (id . 1) (method . ,command) (params . ((source . ,(buffer-substring-no-properties (point-min) (point-max))) (line . ,(line-number-at-pos (point))) (column . ,(- (point) (line-beginning-position))) (path . ,(when (buffer-file-name) (pythonic-file-name (buffer-file-name)))))))) (defun anaconda-mode-create-response-handler (command callback) "Create server response handler based on COMMAND and CALLBACK function. COMMAND argument will be used for response skip message. Response can be skipped if point was moved sense request was submitted." (let ((anaconda-mode-request-point (point)) (anaconda-mode-request-buffer (current-buffer)) (anaconda-mode-request-window (selected-window)) (anaconda-mode-request-tick (buffer-chars-modified-tick))) (lambda (_status) (let ((http-buffer (current-buffer))) (unwind-protect (if (or (not (equal anaconda-mode-request-window (selected-window))) (with-current-buffer (window-buffer anaconda-mode-request-window) (or (not (equal anaconda-mode-request-buffer (current-buffer))) (not (equal anaconda-mode-request-point (point))) (not (equal anaconda-mode-request-tick (buffer-chars-modified-tick)))))) (message "Skip anaconda-mode %s response" command) (goto-char url-http-end-of-headers) (let* ((json-array-type 'list) (response (condition-case nil (json-read) (json-readtable-error (progn (let ((response-string (buffer-string))) (pop-to-buffer (with-current-buffer (get-buffer-create "*anaconda-response*") (insert response-string) (goto-char (point-min)) (current-buffer)))) (error "Can't read anaconda-mode server response")))))) (if (assoc 'error response) (error (cdr (assoc 'error response))) (with-current-buffer anaconda-mode-request-buffer ;; Terminate `apply' call with empty list so response ;; will be treated as single argument. (apply callback (cdr (assoc 'result response)) nil))))) (kill-buffer http-buffer)))))) ;;; Code completion. (defun anaconda-mode-complete () "Request completion candidates." (interactive) (unless (python-syntax-comment-or-string-p) (anaconda-mode-call "complete" anaconda-mode-complete-callback))) (defun anaconda-mode-complete-callback (result) "Start interactive completion on RESULT receiving." (let* ((bounds (bounds-of-thing-at-point 'symbol)) (start (or (car bounds) (point))) (stop (or (cdr bounds) (point))) (collection (anaconda-mode-complete-extract-names result)) (completion-extra-properties '(:annotation-function anaconda-mode-complete-annotation))) (completion-in-region start stop collection))) (defun anaconda-mode-complete-extract-names (result) "Extract completion names from anaconda-mode RESULT." (--map (let* ((name (cdr (assoc 'name it))) (type (cdr (assoc 'type it))) (module-path (cdr (assoc 'module-path it))) (line (cdr (assoc 'line it))) (docstring (cdr (assoc 'docstring it))) (description (if (equal type "statement") "statement" (cdr (assoc 'description it))))) (put-text-property 0 1 'description description name) (put-text-property 0 1 'module-path module-path name) (put-text-property 0 1 'line line name) (put-text-property 0 1 'docstring docstring name) name) result)) (defun anaconda-mode-complete-annotation (candidate) "Get annotation for CANDIDATE." (--when-let (get-text-property 0 'description candidate) (concat " <" it ">"))) ;;; View documentation. (defun anaconda-mode-show-doc () "Show documentation for context at point." (interactive) (anaconda-mode-call "goto_definitions" anaconda-mode-show-doc-callback)) (defun anaconda-mode-show-doc-callback (result) "Process view doc RESULT." (if result (anaconda-mode-documentation-view result) (message "No documentation available"))) ;;; Find definitions. (defun anaconda-mode-find-definitions () "Find definitions for thing at point." (interactive) (anaconda-mode-call "goto_definitions" anaconda-mode-find-definitions-callback)) (defun anaconda-mode-find-definitions-callback (result) "Process find definitions RESULT." (if result (anaconda-mode-definitions-view result) (message "No definitions found"))) ;;; Find assignments. (defun anaconda-mode-find-assignments () "Find assignments for thing at point." (interactive) (anaconda-mode-call "goto_assignments" anaconda-mode-find-assignments-callback)) (defun anaconda-mode-find-assignments-callback (result) "Process find assignments RESULT." (if result (anaconda-mode-definitions-view result) (message "No assignments found"))) ;;; Find references. (defun anaconda-mode-find-references () "Find references for thing at point." (interactive) (anaconda-mode-call "usages" anaconda-mode-find-references-callback)) (defun anaconda-mode-find-references-callback (result) "Process find references RESULT." (if result (anaconda-mode-definitions-view result) (message "No references found"))) ;;; Eldoc. (defun anaconda-mode-eldoc-function () "Show eldoc for context at point." (anaconda-mode-call "eldoc" anaconda-mode-eldoc-callback)) (defun anaconda-mode-eldoc-callback (result) "Display eldoc from server RESULT." (eldoc-message (anaconda-mode-eldoc-format result))) (defun anaconda-mode-eldoc-format (result) "Format eldoc string from RESULT." (when result (let* ((name (cdr (assoc 'name result))) (index (or (cdr (assoc 'index result)) 0)) (params (cdr (assoc 'params result))) (doc (anaconda-mode-eldoc-format-definition name index params))) (if anaconda-mode-eldoc-as-single-line (substring doc 0 (min (frame-width) (length doc))) doc)))) (defun anaconda-mode-eldoc-format-definition (name index params) "Format function definition from NAME, INDEX and PARAMS." (concat (propertize name 'face 'font-lock-function-name-face) "(" (anaconda-mode-eldoc-format-params params index) ")")) (defun anaconda-mode-eldoc-format-params (args index) "Build colorized ARGS string with current arg pointed to INDEX." (->> args (--map-indexed (if (= index it-index) (propertize it 'face 'eldoc-highlight-function-argument) it)) (-interpose ", ") (apply 'concat))) ;;; Result view. (defmacro anaconda-mode-with-view-buffer (&rest body) "Create view buffer and execute BODY in it." `(let ((buf (get-buffer-create "*Anaconda*"))) (with-current-buffer buf (setq buffer-read-only nil) (erase-buffer) ,@body (goto-char (point-min)) (anaconda-mode-view-mode) buf))) (defun anaconda-mode-definitions-view (result) "Show definitions view for rpc RESULT." (if (eq 1 (length result)) (anaconda-mode-find-file (car result)) (anaconda-mode-view result 'anaconda-mode-view-definitions-presenter))) (defun anaconda-mode-documentation-view (result) "Show documentation view for rpc RESULT." (anaconda-mode-view result 'anaconda-mode-view-documentation-presenter)) (defun anaconda-mode-view (result presenter) "Show RESULT to user for future selection. RESULT must be an RESULT field from json-rpc response. PRESENTER is the function used to format buffer content." (pop-to-buffer (anaconda-mode-with-view-buffer (funcall presenter result)))) (defun anaconda-mode-view-make-bold (string) "Make passed STRING look bold." (propertize string 'face 'bold)) (defun anaconda-mode-view-make-source (string) "Make passed STRING look like python source." (with-temp-buffer (insert string) (let ((delay-mode-hooks t)) (python-mode)) (run-hooks 'font-lock-mode-hook) (font-lock-fontify-buffer) (buffer-string))) (define-button-type 'anaconda-mode-definition-button 'action #'anaconda-mode-view-jump 'face nil) (defun anaconda-mode-view-jump (button) "Jump to definition file saved in BUTTON." (let ((definition (button-get button 'definition))) (anaconda-mode-find-file definition))) (defun anaconda-mode-view-jump-other-window (button) "Jump to definition file saved in BUTTON." (let ((definition (button-get button 'definition))) (anaconda-mode-find-file-other-window definition))) (defun anaconda-mode-find-file (definition) "Find DEFINITION file, go to DEFINITION point." (anaconda-mode-find-file-generic definition 'find-file)) (defun anaconda-mode-find-file-other-window (definition) "Find DEFINITION file other window, go to DEFINITION point." (anaconda-mode-find-file-generic definition 'find-file-other-window)) (defvar-local anaconda-mode-go-back-definition nil "Previous definition from which current buffer was navigated.") (defun anaconda-mode-find-file-generic (definition find-function) "Find DEFINITION with FIND-FUNCTION." (let ((backward-navigation (when (buffer-file-name) `((module-path . ,(buffer-file-name)) (line . ,(line-number-at-pos (point))) (column . ,(- (point) (line-beginning-position))))))) (--if-let (cdr (assoc 'module-path definition)) (progn (funcall find-function it) (goto-char 0) (forward-line (1- (cdr (assoc 'line definition)))) (forward-char (cdr (assoc 'column definition))) (setq anaconda-mode-go-back-definition backward-navigation)) (message "Can't open %s module" (cdr (assoc 'module-name definition)))))) (defun anaconda-mode-view-insert-button (name definition) "Insert text button with NAME opening the DEFINITION." (insert-text-button name 'type 'anaconda-mode-definition-button 'definition definition)) (defun anaconda-mode-view-definitions-presenter (result) "Insert definitions from RESULT." (->> (--group-by (cdr (assoc 'module-name it)) result) (--map (anaconda-mode-view-insert-module-definition it)))) (defun anaconda-mode-view-insert-module-definition (module) "Insert MODULE definition into current buffer." (insert (concat (anaconda-mode-view-make-bold (car module)) "\n")) (--map (progn (insert " ") (anaconda-mode-view-insert-button (anaconda-mode-view-make-source (cdr (assoc 'description it))) it) (insert "\n")) (cdr module))) (defun anaconda-mode-view-documentation-presenter (result) "Insert documentation from RESULT." (--map (progn (insert (anaconda-mode-view-make-bold (cdr (assoc 'module-name it)))) (insert "\n") (insert (s-trim-right (cdr (assoc 'docstring it)))) (insert "\n\n")) result)) (defvar anaconda-mode-view-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "n") 'next-error-no-select) (define-key map (kbd "p") 'previous-error-no-select) (define-key map (kbd "q") 'quit-window) map)) (define-derived-mode anaconda-mode-view-mode special-mode "Anaconda-View" "Major mode for definitions view and navigation for `anaconda-mode'. \\{anaconda-mode-view-mode-map}" (setq next-error-function #'anaconda-mode-next-definition)) (defun anaconda-mode-next-definition (num _reset) "Navigate tot the next definition in the view buffer. NUM is the number of definitions to move forward. RESET mean go to the beginning of buffer before definitions navigation." (forward-button num) (anaconda-mode-view-jump-other-window (button-at (point)))) (defun anaconda-mode-go-back () "Jump backward if buffer was navigated from `anaconda-mode' command." (interactive) (if anaconda-mode-go-back-definition (anaconda-mode-find-file anaconda-mode-go-back-definition) (error "No previous buffer"))) ;;; Anaconda minor mode. (defvar anaconda-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "C-M-i") 'anaconda-mode-complete) (define-key map (kbd "M-.") 'anaconda-mode-find-definitions) (define-key map (kbd "M-,") 'anaconda-mode-find-assignments) (define-key map (kbd "M-r") 'anaconda-mode-find-references) (define-key map (kbd "M-*") 'anaconda-mode-go-back) (define-key map (kbd "M-?") 'anaconda-mode-show-doc) map) "Keymap for `anaconda-mode'.") ;;;###autoload (define-minor-mode anaconda-mode "Code navigation, documentation lookup and completion for Python. \\{anaconda-mode-map}" :lighter " Anaconda" :keymap anaconda-mode-map (if anaconda-mode (turn-on-anaconda-mode) (turn-off-anaconda-mode))) (defun turn-on-anaconda-mode () "Turn on `anaconda-mode'." (make-local-variable 'eldoc-documentation-function) (setq-local eldoc-documentation-function 'anaconda-mode-eldoc-function)) (defun turn-off-anaconda-mode () "Turn off `anaconda-mode'." (kill-local-variable 'eldoc-documentation-function)) (provide 'anaconda-mode) ;;; anaconda-mode.el ends here
true
;;; anaconda-mode.el --- Code navigation, documentation lookup and completion for Python -*- lexical-binding: t; -*- ;; Copyright (C) 2013-2015 by PI:NAME:<NAME>END_PI ;; Author: PI:NAME:<NAME>END_PI <PI:EMAIL:<EMAIL>END_PI> ;; URL: https://github.com/proofit404/anaconda-mode ;; Package-Version: 20150922.537 ;; Version: 0.1.1 ;; Package-Requires: ((emacs "24") (pythonic "0.1.0") (dash "2.6.0") (s "1.9") (f "0.16.2")) ;; 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: ;; See the README for more details. ;;; Code: (eval-when-compile (defvar url-http-end-of-headers)) (require 'tramp) (require 'url) (require 'json) (require 'pythonic) (require 'dash) (require 's) (require 'f) (defgroup anaconda-mode nil "Code navigation, documentation lookup and completion for Python." :group 'programming) (defcustom anaconda-mode-installation-directory "~/.emacs.d/anaconda-mode" "Installation directory for anaconda-mode server." :group 'anaconda-mode :type 'directory) (defcustom anaconda-mode-complete-callback 'anaconda-mode-complete-callback "Callback function used to display `anaconda-mode-complete' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-show-doc-callback 'anaconda-mode-show-doc-callback "Callback function used to display `anaconda-mode-show-doc' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-find-definitions-callback 'anaconda-mode-find-definitions-callback "Callback function used to display `anaconda-mode-find-definitions' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-find-assignments-callback 'anaconda-mode-find-assignments-callback "Callback function used to display `anaconda-mode-find-assignments' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-find-references-callback 'anaconda-mode-find-references-callback "Callback function used to display `anaconda-mode-find-references' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-eldoc-callback 'anaconda-mode-eldoc-callback "Callback function used to display `anaconda-mode-eldoc-function' result." :group 'anaconda-mode :type 'function) (defcustom anaconda-mode-eldoc-as-single-line nil "If not nil, trim eldoc string to frame width." :group 'anaconda-mode :type 'boolean) ;;; Server. (defvar anaconda-mode-server-version "0.1.1" "Server version needed to run anaconda-mode.") (defvar anaconda-mode-server-script "anaconda_mode.py" "Script file with anaconda-mode server.") (defvar anaconda-mode-process-name "anaconda-mode" "Process name for anaconda-mode processes.") (defvar anaconda-mode-process-buffer "*anaconda-mode*" "Buffer name for anaconda-mode processes.") (defvar anaconda-mode-process nil "Currently running anaconda-mode process.") (defvar anaconda-mode-port nil "Port for anaconda-mode connection.") (defvar anaconda-mode-ensure-directory-command " import os import sys directory = sys.argv[-1] if not os.path.exists(directory): os.makedirs(directory) " "Create `anaconda-mode-server-directory' if necessary.") (defvar anaconda-mode-check-installation-command " import sys, os from pkg_resources import find_distributions directory = sys.argv[-1] for dist in find_distributions(directory, only=True): if dist.project_name == 'anaconda-mode': break else: # IPython patch sys.exit, so we can't use it. os._exit(1) " "Check if `anaconda-mode' server is installed or not.") (defvar anaconda-mode-install-server-command " import sys import pip directory = sys.argv[-2] version = sys.argv[-1] pip.main(['install', '-t', directory, 'anaconda_mode==' + version]) " "Install `anaconda_mode' server.") (defun anaconda-mode-server-directory () "Anaconda mode installation directory." (f-join anaconda-mode-installation-directory anaconda-mode-server-version)) (defun anaconda-mode-host () "Target host with anaconda-mode server." (if (pythonic-remote-p) (tramp-file-name-host (tramp-dissect-file-name (pythonic-tramp-connection))) "127.0.0.1")) (defun anaconda-mode-start (&optional callback) "Start anaconda-mode server. CALLBACK function will be called when `anaconda-mode-port' will be bound." (when (anaconda-mode-need-restart) (anaconda-mode-stop)) (if (anaconda-mode-running-p) (when callback (funcall callback)) (anaconda-mode-ensure-directory callback))) (defun anaconda-mode-stop () "Stop anaconda-mode server." (when (anaconda-mode-running-p) (set-process-filter anaconda-mode-process nil) (set-process-sentinel anaconda-mode-process nil) (kill-process anaconda-mode-process) (setq anaconda-mode-process nil anaconda-mode-port nil))) (defun anaconda-mode-running-p () "Is `anaconda-mode' server running." (and anaconda-mode-process (process-live-p anaconda-mode-process))) (defun anaconda-mode-bound-p () "Is `anaconda-mode' port bound." (numberp anaconda-mode-port)) (defun anaconda-mode-need-restart () "Check if we need to restart `anaconda-mode-server'." (when (and (anaconda-mode-running-p) (anaconda-mode-bound-p)) (or (not (pythonic-proper-environment-p anaconda-mode-process)) (not (equal (process-get anaconda-mode-process 'server-directory) (anaconda-mode-server-directory)))))) (defun anaconda-mode-ensure-directory (&optional callback) "Ensure if `anaconda-mode-server-directory' exists. CALLBACK function will be called when `anaconda-mode-port' will be bound." (setq anaconda-mode-process (start-pythonic :process anaconda-mode-process-name :buffer anaconda-mode-process-buffer :sentinel (lambda (process event) (anaconda-mode-ensure-directory-sentinel process event callback)) :args (list "-c" anaconda-mode-ensure-directory-command (anaconda-mode-server-directory))))) (defun anaconda-mode-ensure-directory-sentinel (process _event &optional callback) "Run `anaconda-mode-check' if `anaconda-mode-server-directory' exists. Raise error otherwise. PROCESS and EVENT are basic sentinel parameters. CALLBACK function will be called when `anaconda-mode-port' will be bound." (if (eq 0 (process-exit-status process)) (anaconda-mode-check callback) (pop-to-buffer anaconda-mode-process-buffer) (error "Can't create %s directory" (anaconda-mode-server-directory)))) (defun anaconda-mode-check (&optional callback) "Check `anaconda-mode' server installation. CALLBACK function will be called when `anaconda-mode-port' will be bound." (setq anaconda-mode-process (start-pythonic :process anaconda-mode-process-name :buffer anaconda-mode-process-buffer :sentinel (lambda (process event) (anaconda-mode-check-sentinel process event callback)) :args (list "-c" anaconda-mode-check-installation-command (anaconda-mode-server-directory))))) (defun anaconda-mode-check-sentinel (process _event &optional callback) "Run `anaconda-mode-bootstrap' if server installation check passed. Try to install `anaconda-mode' server otherwise. PROCESS and EVENT are basic sentinel parameters. CALLBACK function will be called when `anaconda-mode-port' will be bound." (if (eq 0 (process-exit-status process)) (anaconda-mode-bootstrap callback) (anaconda-mode-install callback))) (defun anaconda-mode-install (&optional callback) "Try to install `anaconda-mode' server. CALLBACK function will be called when `anaconda-mode-port' will be bound." (setq anaconda-mode-process (start-pythonic :process anaconda-mode-process-name :buffer anaconda-mode-process-buffer :sentinel (lambda (process event) (anaconda-mode-install-sentinel process event callback)) :args (list "-c" anaconda-mode-install-server-command (anaconda-mode-server-directory) anaconda-mode-server-version)))) (defun anaconda-mode-install-sentinel (process _event &optional callback) "Run `anaconda-mode-bootstrap' if server installation complete successfully. Raise error otherwise. PROCESS and EVENT are basic sentinel parameters. CALLBACK function will be called when `anaconda-mode-port' will be bound." (if (eq 0 (process-exit-status process)) (anaconda-mode-bootstrap callback) (pop-to-buffer anaconda-mode-process-buffer) (error "Can't install `anaconda-mode' server"))) (defun anaconda-mode-bootstrap (&optional callback) "Run `anaconda-mode' server. CALLBACK function will be called when `anaconda-mode-port' will be bound." (setq anaconda-mode-process (start-pythonic :process anaconda-mode-process-name :buffer anaconda-mode-process-buffer :cwd (anaconda-mode-server-directory) :filter (lambda (process output) (anaconda-mode-bootstrap-filter process output callback)) :sentinel 'anaconda-mode-bootstrap-sentinel :query-on-exit nil :args (list anaconda-mode-server-script))) (process-put anaconda-mode-process 'server-directory (anaconda-mode-server-directory))) (defun anaconda-mode-bootstrap-filter (process output &optional callback) "Set `anaconda-mode-port' from PROCESS OUTPUT. Connect to the `anaconda-mode' server. CALLBACK function will be called when `anaconda-mode-port' will be bound." ;; Mimic default filter. (when (buffer-live-p (process-buffer process)) (with-current-buffer (process-buffer process) (save-excursion (goto-char (process-mark process)) (insert output) (set-marker (process-mark process) (point))))) (--when-let (s-match "anaconda_mode port \\([0-9]+\\)" output) (setq anaconda-mode-port (string-to-number (cadr it))) (set-process-filter process nil) (when callback (funcall callback)))) (defun anaconda-mode-bootstrap-sentinel (process _event) "Raise error if `anaconda-mode' server exit abnormally. PROCESS and EVENT are basic sentinel parameters." (unless (eq 0 (process-exit-status process)) (pop-to-buffer anaconda-mode-process-buffer) (error "Can't start `anaconda-mode' server"))) ;;; Interaction. (defun anaconda-mode-call (command callback) "Make remote procedure call for COMMAND. Apply CALLBACK to it result." (anaconda-mode-start (lambda () (anaconda-mode-jsonrpc command callback)))) (defun anaconda-mode-jsonrpc (command callback) "Perform JSONRPC call for COMMAND. Apply CALLBACK to the call result when retrieve it. Remote COMMAND must expect four arguments: python buffer content, line number position, column number position and file path." (let ((url-request-method "POST") (url-request-data (anaconda-mode-jsonrpc-request command))) (url-retrieve (format "http://%s:%s" (anaconda-mode-host) anaconda-mode-port) (anaconda-mode-create-response-handler command callback) nil t))) (defun anaconda-mode-jsonrpc-request (command) "Prepare JSON encoded buffer data for COMMAND call." (json-encode (anaconda-mode-jsonrpc-request-data command))) (defun anaconda-mode-jsonrpc-request-data (command) "Prepare buffer data for COMMAND call." `((jsonrpc . "2.0") (id . 1) (method . ,command) (params . ((source . ,(buffer-substring-no-properties (point-min) (point-max))) (line . ,(line-number-at-pos (point))) (column . ,(- (point) (line-beginning-position))) (path . ,(when (buffer-file-name) (pythonic-file-name (buffer-file-name)))))))) (defun anaconda-mode-create-response-handler (command callback) "Create server response handler based on COMMAND and CALLBACK function. COMMAND argument will be used for response skip message. Response can be skipped if point was moved sense request was submitted." (let ((anaconda-mode-request-point (point)) (anaconda-mode-request-buffer (current-buffer)) (anaconda-mode-request-window (selected-window)) (anaconda-mode-request-tick (buffer-chars-modified-tick))) (lambda (_status) (let ((http-buffer (current-buffer))) (unwind-protect (if (or (not (equal anaconda-mode-request-window (selected-window))) (with-current-buffer (window-buffer anaconda-mode-request-window) (or (not (equal anaconda-mode-request-buffer (current-buffer))) (not (equal anaconda-mode-request-point (point))) (not (equal anaconda-mode-request-tick (buffer-chars-modified-tick)))))) (message "Skip anaconda-mode %s response" command) (goto-char url-http-end-of-headers) (let* ((json-array-type 'list) (response (condition-case nil (json-read) (json-readtable-error (progn (let ((response-string (buffer-string))) (pop-to-buffer (with-current-buffer (get-buffer-create "*anaconda-response*") (insert response-string) (goto-char (point-min)) (current-buffer)))) (error "Can't read anaconda-mode server response")))))) (if (assoc 'error response) (error (cdr (assoc 'error response))) (with-current-buffer anaconda-mode-request-buffer ;; Terminate `apply' call with empty list so response ;; will be treated as single argument. (apply callback (cdr (assoc 'result response)) nil))))) (kill-buffer http-buffer)))))) ;;; Code completion. (defun anaconda-mode-complete () "Request completion candidates." (interactive) (unless (python-syntax-comment-or-string-p) (anaconda-mode-call "complete" anaconda-mode-complete-callback))) (defun anaconda-mode-complete-callback (result) "Start interactive completion on RESULT receiving." (let* ((bounds (bounds-of-thing-at-point 'symbol)) (start (or (car bounds) (point))) (stop (or (cdr bounds) (point))) (collection (anaconda-mode-complete-extract-names result)) (completion-extra-properties '(:annotation-function anaconda-mode-complete-annotation))) (completion-in-region start stop collection))) (defun anaconda-mode-complete-extract-names (result) "Extract completion names from anaconda-mode RESULT." (--map (let* ((name (cdr (assoc 'name it))) (type (cdr (assoc 'type it))) (module-path (cdr (assoc 'module-path it))) (line (cdr (assoc 'line it))) (docstring (cdr (assoc 'docstring it))) (description (if (equal type "statement") "statement" (cdr (assoc 'description it))))) (put-text-property 0 1 'description description name) (put-text-property 0 1 'module-path module-path name) (put-text-property 0 1 'line line name) (put-text-property 0 1 'docstring docstring name) name) result)) (defun anaconda-mode-complete-annotation (candidate) "Get annotation for CANDIDATE." (--when-let (get-text-property 0 'description candidate) (concat " <" it ">"))) ;;; View documentation. (defun anaconda-mode-show-doc () "Show documentation for context at point." (interactive) (anaconda-mode-call "goto_definitions" anaconda-mode-show-doc-callback)) (defun anaconda-mode-show-doc-callback (result) "Process view doc RESULT." (if result (anaconda-mode-documentation-view result) (message "No documentation available"))) ;;; Find definitions. (defun anaconda-mode-find-definitions () "Find definitions for thing at point." (interactive) (anaconda-mode-call "goto_definitions" anaconda-mode-find-definitions-callback)) (defun anaconda-mode-find-definitions-callback (result) "Process find definitions RESULT." (if result (anaconda-mode-definitions-view result) (message "No definitions found"))) ;;; Find assignments. (defun anaconda-mode-find-assignments () "Find assignments for thing at point." (interactive) (anaconda-mode-call "goto_assignments" anaconda-mode-find-assignments-callback)) (defun anaconda-mode-find-assignments-callback (result) "Process find assignments RESULT." (if result (anaconda-mode-definitions-view result) (message "No assignments found"))) ;;; Find references. (defun anaconda-mode-find-references () "Find references for thing at point." (interactive) (anaconda-mode-call "usages" anaconda-mode-find-references-callback)) (defun anaconda-mode-find-references-callback (result) "Process find references RESULT." (if result (anaconda-mode-definitions-view result) (message "No references found"))) ;;; Eldoc. (defun anaconda-mode-eldoc-function () "Show eldoc for context at point." (anaconda-mode-call "eldoc" anaconda-mode-eldoc-callback)) (defun anaconda-mode-eldoc-callback (result) "Display eldoc from server RESULT." (eldoc-message (anaconda-mode-eldoc-format result))) (defun anaconda-mode-eldoc-format (result) "Format eldoc string from RESULT." (when result (let* ((name (cdr (assoc 'name result))) (index (or (cdr (assoc 'index result)) 0)) (params (cdr (assoc 'params result))) (doc (anaconda-mode-eldoc-format-definition name index params))) (if anaconda-mode-eldoc-as-single-line (substring doc 0 (min (frame-width) (length doc))) doc)))) (defun anaconda-mode-eldoc-format-definition (name index params) "Format function definition from NAME, INDEX and PARAMS." (concat (propertize name 'face 'font-lock-function-name-face) "(" (anaconda-mode-eldoc-format-params params index) ")")) (defun anaconda-mode-eldoc-format-params (args index) "Build colorized ARGS string with current arg pointed to INDEX." (->> args (--map-indexed (if (= index it-index) (propertize it 'face 'eldoc-highlight-function-argument) it)) (-interpose ", ") (apply 'concat))) ;;; Result view. (defmacro anaconda-mode-with-view-buffer (&rest body) "Create view buffer and execute BODY in it." `(let ((buf (get-buffer-create "*Anaconda*"))) (with-current-buffer buf (setq buffer-read-only nil) (erase-buffer) ,@body (goto-char (point-min)) (anaconda-mode-view-mode) buf))) (defun anaconda-mode-definitions-view (result) "Show definitions view for rpc RESULT." (if (eq 1 (length result)) (anaconda-mode-find-file (car result)) (anaconda-mode-view result 'anaconda-mode-view-definitions-presenter))) (defun anaconda-mode-documentation-view (result) "Show documentation view for rpc RESULT." (anaconda-mode-view result 'anaconda-mode-view-documentation-presenter)) (defun anaconda-mode-view (result presenter) "Show RESULT to user for future selection. RESULT must be an RESULT field from json-rpc response. PRESENTER is the function used to format buffer content." (pop-to-buffer (anaconda-mode-with-view-buffer (funcall presenter result)))) (defun anaconda-mode-view-make-bold (string) "Make passed STRING look bold." (propertize string 'face 'bold)) (defun anaconda-mode-view-make-source (string) "Make passed STRING look like python source." (with-temp-buffer (insert string) (let ((delay-mode-hooks t)) (python-mode)) (run-hooks 'font-lock-mode-hook) (font-lock-fontify-buffer) (buffer-string))) (define-button-type 'anaconda-mode-definition-button 'action #'anaconda-mode-view-jump 'face nil) (defun anaconda-mode-view-jump (button) "Jump to definition file saved in BUTTON." (let ((definition (button-get button 'definition))) (anaconda-mode-find-file definition))) (defun anaconda-mode-view-jump-other-window (button) "Jump to definition file saved in BUTTON." (let ((definition (button-get button 'definition))) (anaconda-mode-find-file-other-window definition))) (defun anaconda-mode-find-file (definition) "Find DEFINITION file, go to DEFINITION point." (anaconda-mode-find-file-generic definition 'find-file)) (defun anaconda-mode-find-file-other-window (definition) "Find DEFINITION file other window, go to DEFINITION point." (anaconda-mode-find-file-generic definition 'find-file-other-window)) (defvar-local anaconda-mode-go-back-definition nil "Previous definition from which current buffer was navigated.") (defun anaconda-mode-find-file-generic (definition find-function) "Find DEFINITION with FIND-FUNCTION." (let ((backward-navigation (when (buffer-file-name) `((module-path . ,(buffer-file-name)) (line . ,(line-number-at-pos (point))) (column . ,(- (point) (line-beginning-position))))))) (--if-let (cdr (assoc 'module-path definition)) (progn (funcall find-function it) (goto-char 0) (forward-line (1- (cdr (assoc 'line definition)))) (forward-char (cdr (assoc 'column definition))) (setq anaconda-mode-go-back-definition backward-navigation)) (message "Can't open %s module" (cdr (assoc 'module-name definition)))))) (defun anaconda-mode-view-insert-button (name definition) "Insert text button with NAME opening the DEFINITION." (insert-text-button name 'type 'anaconda-mode-definition-button 'definition definition)) (defun anaconda-mode-view-definitions-presenter (result) "Insert definitions from RESULT." (->> (--group-by (cdr (assoc 'module-name it)) result) (--map (anaconda-mode-view-insert-module-definition it)))) (defun anaconda-mode-view-insert-module-definition (module) "Insert MODULE definition into current buffer." (insert (concat (anaconda-mode-view-make-bold (car module)) "\n")) (--map (progn (insert " ") (anaconda-mode-view-insert-button (anaconda-mode-view-make-source (cdr (assoc 'description it))) it) (insert "\n")) (cdr module))) (defun anaconda-mode-view-documentation-presenter (result) "Insert documentation from RESULT." (--map (progn (insert (anaconda-mode-view-make-bold (cdr (assoc 'module-name it)))) (insert "\n") (insert (s-trim-right (cdr (assoc 'docstring it)))) (insert "\n\n")) result)) (defvar anaconda-mode-view-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "n") 'next-error-no-select) (define-key map (kbd "p") 'previous-error-no-select) (define-key map (kbd "q") 'quit-window) map)) (define-derived-mode anaconda-mode-view-mode special-mode "Anaconda-View" "Major mode for definitions view and navigation for `anaconda-mode'. \\{anaconda-mode-view-mode-map}" (setq next-error-function #'anaconda-mode-next-definition)) (defun anaconda-mode-next-definition (num _reset) "Navigate tot the next definition in the view buffer. NUM is the number of definitions to move forward. RESET mean go to the beginning of buffer before definitions navigation." (forward-button num) (anaconda-mode-view-jump-other-window (button-at (point)))) (defun anaconda-mode-go-back () "Jump backward if buffer was navigated from `anaconda-mode' command." (interactive) (if anaconda-mode-go-back-definition (anaconda-mode-find-file anaconda-mode-go-back-definition) (error "No previous buffer"))) ;;; Anaconda minor mode. (defvar anaconda-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "C-M-i") 'anaconda-mode-complete) (define-key map (kbd "M-.") 'anaconda-mode-find-definitions) (define-key map (kbd "M-,") 'anaconda-mode-find-assignments) (define-key map (kbd "M-r") 'anaconda-mode-find-references) (define-key map (kbd "M-*") 'anaconda-mode-go-back) (define-key map (kbd "M-?") 'anaconda-mode-show-doc) map) "Keymap for `anaconda-mode'.") ;;;###autoload (define-minor-mode anaconda-mode "Code navigation, documentation lookup and completion for Python. \\{anaconda-mode-map}" :lighter " Anaconda" :keymap anaconda-mode-map (if anaconda-mode (turn-on-anaconda-mode) (turn-off-anaconda-mode))) (defun turn-on-anaconda-mode () "Turn on `anaconda-mode'." (make-local-variable 'eldoc-documentation-function) (setq-local eldoc-documentation-function 'anaconda-mode-eldoc-function)) (defun turn-off-anaconda-mode () "Turn off `anaconda-mode'." (kill-local-variable 'eldoc-documentation-function)) (provide 'anaconda-mode) ;;; anaconda-mode.el ends here
[ { "context": "ub.com/Groovy-Emacs-Modes/groovy-emacs-modes\n;;\n;; Paolo de Dios <[email protected]>\n;;;;;;;;;;;;;;;;;;;;;;;;;", "end": 130, "score": 0.999899685382843, "start": 117, "tag": "NAME", "value": "Paolo de Dios" }, { "context": "acs-Modes/groovy-emacs-modes\n;;\n;; Paolo de Dios <[email protected]>\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;", "end": 153, "score": 0.9999245405197144, "start": 132, "tag": "EMAIL", "value": "[email protected]" } ]
.emacs.d/modules/config-groovy-mode.el
paolodedios/dot-files
0
;; -*- mode: emacs-lisp -*- ;; ;; Groovy mode ;; @see https://github.com/Groovy-Emacs-Modes/groovy-emacs-modes ;; ;; Paolo de Dios <[email protected]> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (require 'groovy-electric) (autoload 'groovy-mode "groovy-mode" "Groovy Editing Mode" t) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Groovy hook section, called on entry of Groovy mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (add-hook 'groovy-mode-hook '(lambda () (groovy-electric-mode 1) (c-add-style "sourcery" my-java-mode-programming-style t) (c-set-style "sourcery" ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Turn on font-lock ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (add-hook 'groovy-mode-hook 'turn-on-font-lock) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; File associations ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq auto-mode-alist (append '(("\\.groovy$" . groovy-mode )) auto-mode-alist)) (setq auto-mode-alist (append '(("\\.gradle$" . groovy-mode )) auto-mode-alist)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Interpreter binding ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq interpreter-mode-alist (append '(("groovy" . groovy-mode )) interpreter-mode-alist)) (setq interpreter-mode-alist (append '(("gradle" . groovy-mode )) interpreter-mode-alist))
3748
;; -*- mode: emacs-lisp -*- ;; ;; Groovy mode ;; @see https://github.com/Groovy-Emacs-Modes/groovy-emacs-modes ;; ;; <NAME> <<EMAIL>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (require 'groovy-electric) (autoload 'groovy-mode "groovy-mode" "Groovy Editing Mode" t) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Groovy hook section, called on entry of Groovy mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (add-hook 'groovy-mode-hook '(lambda () (groovy-electric-mode 1) (c-add-style "sourcery" my-java-mode-programming-style t) (c-set-style "sourcery" ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Turn on font-lock ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (add-hook 'groovy-mode-hook 'turn-on-font-lock) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; File associations ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq auto-mode-alist (append '(("\\.groovy$" . groovy-mode )) auto-mode-alist)) (setq auto-mode-alist (append '(("\\.gradle$" . groovy-mode )) auto-mode-alist)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Interpreter binding ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq interpreter-mode-alist (append '(("groovy" . groovy-mode )) interpreter-mode-alist)) (setq interpreter-mode-alist (append '(("gradle" . groovy-mode )) interpreter-mode-alist))
true
;; -*- mode: emacs-lisp -*- ;; ;; Groovy mode ;; @see https://github.com/Groovy-Emacs-Modes/groovy-emacs-modes ;; ;; PI:NAME:<NAME>END_PI <PI:EMAIL:<EMAIL>END_PI> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (require 'groovy-electric) (autoload 'groovy-mode "groovy-mode" "Groovy Editing Mode" t) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Groovy hook section, called on entry of Groovy mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (add-hook 'groovy-mode-hook '(lambda () (groovy-electric-mode 1) (c-add-style "sourcery" my-java-mode-programming-style t) (c-set-style "sourcery" ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Turn on font-lock ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (add-hook 'groovy-mode-hook 'turn-on-font-lock) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; File associations ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq auto-mode-alist (append '(("\\.groovy$" . groovy-mode )) auto-mode-alist)) (setq auto-mode-alist (append '(("\\.gradle$" . groovy-mode )) auto-mode-alist)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Interpreter binding ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq interpreter-mode-alist (append '(("groovy" . groovy-mode )) interpreter-mode-alist)) (setq interpreter-mode-alist (append '(("gradle" . groovy-mode )) interpreter-mode-alist))
[ { "context": "figuration for es-mode\n;;; Commentary:\n;;; Author: Vedang Manerikar\n;;; Created on: 9 Jul 2016\n;;; Copyright (c) 2016", "end": 94, "score": 0.9998958110809326, "start": 78, "tag": "NAME", "value": "Vedang Manerikar" }, { "context": "\n;;; Created on: 9 Jul 2016\n;;; Copyright (c) 2016 Vedang Manerikar <[email protected]>\n\n;; This file is not", "end": 161, "score": 0.9998972415924072, "start": 145, "tag": "NAME", "value": "Vedang Manerikar" }, { "context": "Jul 2016\n;;; Copyright (c) 2016 Vedang Manerikar <[email protected]>\n\n;; This file is not part of GNU Emacs.\n\n;;; Lic", "end": 189, "score": 0.9999362230300903, "start": 163, "tag": "EMAIL", "value": "[email protected]" } ]
el-get-init-files/init-es-mode.el
vedang/emacs-up
13
;;; init-es-mode.el --- Configuration for es-mode ;;; Commentary: ;;; Author: Vedang Manerikar ;;; Created on: 9 Jul 2016 ;;; Copyright (c) 2016 Vedang Manerikar <[email protected]> ;; This file is not part of GNU Emacs. ;;; License: ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the Do What The Fuck You Want to ;; Public License, Version 2, which is included with this distribution. ;; See the file LICENSE.txt ;;; Code: (add-to-list 'auto-mode-alist '("\\.es$" . es-mode)) (setq es-always-pretty-print t) (eval-after-load 'es-cc '(progn (setq es-cc-endpoint "http://shiva.local:9202"))) (provide 'init-es-mode) ;;; init-es-mode.el ends here
23230
;;; init-es-mode.el --- Configuration for es-mode ;;; Commentary: ;;; Author: <NAME> ;;; Created on: 9 Jul 2016 ;;; Copyright (c) 2016 <NAME> <<EMAIL>> ;; This file is not part of GNU Emacs. ;;; License: ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the Do What The Fuck You Want to ;; Public License, Version 2, which is included with this distribution. ;; See the file LICENSE.txt ;;; Code: (add-to-list 'auto-mode-alist '("\\.es$" . es-mode)) (setq es-always-pretty-print t) (eval-after-load 'es-cc '(progn (setq es-cc-endpoint "http://shiva.local:9202"))) (provide 'init-es-mode) ;;; init-es-mode.el ends here
true
;;; init-es-mode.el --- Configuration for es-mode ;;; Commentary: ;;; Author: PI:NAME:<NAME>END_PI ;;; Created on: 9 Jul 2016 ;;; Copyright (c) 2016 PI:NAME:<NAME>END_PI <PI:EMAIL:<EMAIL>END_PI> ;; This file is not part of GNU Emacs. ;;; License: ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the Do What The Fuck You Want to ;; Public License, Version 2, which is included with this distribution. ;; See the file LICENSE.txt ;;; Code: (add-to-list 'auto-mode-alist '("\\.es$" . es-mode)) (setq es-always-pretty-print t) (eval-after-load 'es-cc '(progn (setq es-cc-endpoint "http://shiva.local:9202"))) (provide 'init-es-mode) ;;; init-es-mode.el ends here
[ { "context": "97,1998 Free Software Foundation, Inc.\n\n;; Author: MORIOKA Tomohiko <[email protected]>\n;; Keywords: invisible, tex", "end": 161, "score": 0.9998050928115845, "start": 145, "tag": "NAME", "value": "MORIOKA Tomohiko" }, { "context": "re Foundation, Inc.\n\n;; Author: MORIOKA Tomohiko <[email protected]>\n;; Keywords: invisible, text-property, region, E", "end": 182, "score": 0.9999324083328247, "start": 163, "tag": "EMAIL", "value": "[email protected]" } ]
.emacs.d/lib/apel-10.8/inv-18.el
thayamizu/dotfiles
0
;;; inv-18.el --- invisible feature implementation for Emacs 18 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc. ;; Author: MORIOKA Tomohiko <[email protected]> ;; Keywords: invisible, text-property, region, Emacs 18 ;; This file is part of APEL (A Portable Emacs Library). ;; 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 2, 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 GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Code: (require 'poe) (defun enable-invisible () (make-local-variable 'original-selective-display) (setq original-selective-display selective-display) (setq selective-display t)) (defun disable-invisible () (setq selective-display (and (boundp 'original-selective-display) original-selective-display))) (defalias 'end-of-invisible 'disable-invisible) (make-obsolete 'end-of-invisible 'disable-invisible) (defun invisible-region (start end) (let ((buffer-read-only nil) (modp (buffer-modified-p))) (if (save-excursion (goto-char (1- end)) (eq (following-char) ?\n)) (setq end (1- end))) (unwind-protect (subst-char-in-region start end ?\n ?\r t) (set-buffer-modified-p modp)))) (defun visible-region (start end) (let ((buffer-read-only nil) (modp (buffer-modified-p))) (unwind-protect (subst-char-in-region start end ?\r ?\n t) (set-buffer-modified-p modp)))) (defun invisible-p (pos) (save-excursion (goto-char pos) (eq (following-char) ?\r))) (defun next-visible-point (pos) (save-excursion (goto-char pos) (end-of-line) (if (eq (following-char) ?\n) (forward-char)) (point))) ;;; @ end ;;; (require 'product) (product-provide (provide 'inv-18) (require 'apel-ver)) ;;; inv-18.el ends here
46007
;;; inv-18.el --- invisible feature implementation for Emacs 18 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc. ;; Author: <NAME> <<EMAIL>> ;; Keywords: invisible, text-property, region, Emacs 18 ;; This file is part of APEL (A Portable Emacs Library). ;; 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 2, 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 GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Code: (require 'poe) (defun enable-invisible () (make-local-variable 'original-selective-display) (setq original-selective-display selective-display) (setq selective-display t)) (defun disable-invisible () (setq selective-display (and (boundp 'original-selective-display) original-selective-display))) (defalias 'end-of-invisible 'disable-invisible) (make-obsolete 'end-of-invisible 'disable-invisible) (defun invisible-region (start end) (let ((buffer-read-only nil) (modp (buffer-modified-p))) (if (save-excursion (goto-char (1- end)) (eq (following-char) ?\n)) (setq end (1- end))) (unwind-protect (subst-char-in-region start end ?\n ?\r t) (set-buffer-modified-p modp)))) (defun visible-region (start end) (let ((buffer-read-only nil) (modp (buffer-modified-p))) (unwind-protect (subst-char-in-region start end ?\r ?\n t) (set-buffer-modified-p modp)))) (defun invisible-p (pos) (save-excursion (goto-char pos) (eq (following-char) ?\r))) (defun next-visible-point (pos) (save-excursion (goto-char pos) (end-of-line) (if (eq (following-char) ?\n) (forward-char)) (point))) ;;; @ end ;;; (require 'product) (product-provide (provide 'inv-18) (require 'apel-ver)) ;;; inv-18.el ends here
true
;;; inv-18.el --- invisible feature implementation for Emacs 18 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc. ;; Author: PI:NAME:<NAME>END_PI <PI:EMAIL:<EMAIL>END_PI> ;; Keywords: invisible, text-property, region, Emacs 18 ;; This file is part of APEL (A Portable Emacs Library). ;; 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 2, 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 GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Code: (require 'poe) (defun enable-invisible () (make-local-variable 'original-selective-display) (setq original-selective-display selective-display) (setq selective-display t)) (defun disable-invisible () (setq selective-display (and (boundp 'original-selective-display) original-selective-display))) (defalias 'end-of-invisible 'disable-invisible) (make-obsolete 'end-of-invisible 'disable-invisible) (defun invisible-region (start end) (let ((buffer-read-only nil) (modp (buffer-modified-p))) (if (save-excursion (goto-char (1- end)) (eq (following-char) ?\n)) (setq end (1- end))) (unwind-protect (subst-char-in-region start end ?\n ?\r t) (set-buffer-modified-p modp)))) (defun visible-region (start end) (let ((buffer-read-only nil) (modp (buffer-modified-p))) (unwind-protect (subst-char-in-region start end ?\r ?\n t) (set-buffer-modified-p modp)))) (defun invisible-p (pos) (save-excursion (goto-char pos) (eq (following-char) ?\r))) (defun next-visible-point (pos) (save-excursion (goto-char pos) (end-of-line) (if (eq (following-char) ?\n) (forward-char)) (point))) ;;; @ end ;;; (require 'product) (product-provide (provide 'inv-18) (require 'apel-ver)) ;;; inv-18.el ends here
[ { "context": "5--2021 Free Software Foundation, Inc.\n\n;; Author: Arash Esbati <[email protected]>\n;; Maintainer: [email protected]", "end": 172, "score": 0.9998809099197388, "start": 160, "tag": "NAME", "value": "Arash Esbati" }, { "context": "ftware Foundation, Inc.\n\n;; Author: Arash Esbati <[email protected]>\n;; Maintainer: [email protected]\n;; Created: ", "end": 187, "score": 0.9999334216117859, "start": 174, "tag": "EMAIL", "value": "[email protected]" }, { "context": "uthor: Arash Esbati <[email protected]>\n;; Maintainer: [email protected]\n;; Created: 2014-10-20\n;; Keywords: tex\n\n;; This ", "end": 224, "score": 0.9999287128448486, "start": 204, "tag": "EMAIL", "value": "[email protected]" }, { "context": "eX-enumitem-SetLabelAlign-list)\n (let* ((key \"align\")\n (vals (mapcar #'car (LaTeX-enumitem", "end": 6166, "score": 0.8160274028778076, "start": 6161, "tag": "KEY", "value": "align" } ]
elpa/auctex-13.1.1/style/enumitem.el
timmli/emacs-settings
0
;;; enumitem.el --- AUCTeX style for `enumitem.sty' (v3.9) -*- lexical-binding: t; -*- ;; Copyright (C) 2015--2021 Free Software Foundation, Inc. ;; Author: Arash Esbati <[email protected]> ;; Maintainer: [email protected] ;; Created: 2014-10-20 ;; Keywords: tex ;; This file is part of AUCTeX. ;; AUCTeX 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, or (at your option) ;; any later version. ;; AUCTeX 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 AUCTeX; see the file COPYING. If not, write to the Free ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA ;; 02110-1301, USA. ;;; Commentary: ;; This file adds support for `enumitem.sty' (v3.9) from 2019/06/20. ;; `enumitem.sty' is part of TeXLive. ;; Tassilo Horn's `minted.el' was a major source of inspiration for ;; this style, many thanks to him (also for patiently answering my ;; many other questions, incl. the stupid ones.) ;; If things do not work or when in doubt, press `C-c C-n'. Comments ;; for improvement are welcome. ;;; Code: (require 'tex) (require 'latex) (eval-when-compile (require 'cl-lib)) ;; Silence the compiler: (declare-function font-latex-add-keywords "font-latex" (keywords class)) (defvar LaTeX-enumitem-key-val-options `(;; 3.1 Label and cross references format ("label" ("\\alph*" "\\Alph*" "\\arabic*" "\\roman*" "\\Roman*" "\\value*")) ("label*" ("\\alph*" "\\Alph*" "\\arabic*" "\\roman*" "\\Roman*" "\\value*")) ("ref" ("\\alph*" "\\Alph*" "\\arabic*" "\\roman*" "\\Roman*" "\\value*")) ("font" ,(mapcar (lambda (mac) (concat TeX-esc mac)) '(;; family "rmfamily" "sffamily" "ttfamily" ;; series "mdseries" "bfseries" ;; shape "upshape" "itshape" "slshape" "scshape" ;; size "tiny" "scriptsize" "footnotesize" "small" "normalsize" "large" "Large" "LARGE" "huge" "Huge" ;; reset macro "normalfont"))) ("format" ,(mapcar (lambda (mac) (concat TeX-esc mac)) '(;; family "rmfamily" "sffamily" "ttfamily" ;; series "mdseries" "bfseries" ;; shape "upshape" "itshape" "slshape" "scshape" ;; size "tiny" "scriptsize" "footnotesize" "small" "normalsize" "large" "Large" "LARGE" "huge" "Huge" ;; reset macro "normalfont"))) ("align" ("left" "right" "parleft")) ;; 3.2 Horizontal spacing of labels ("labelindent" ("*" "!")) ("left") ("leftmargin" ("*" "!")) ("itemindent" ("*" "!")) ("labelsep" ("*" "!")) ("labelwidth" ("*" "!")) ("widest") ("widest*") ("labelsep*") ("labelindent*") ("rightmargin") ;; Vertical Spacing ("topsep") ("partopsep") ("parsep") ("itemsep") ;; 3.3 Numbering, stopping, and resuming ("start") ("resume") ("resume*") ;; 3.4 Series ("series") ;; 3.5 Penalties ("beginpenalty") ("midpenalty") ("endpenalty") ;; 3.6 Injecting code ("before") ("before*") ("after") ("after*") ("first") ("first*") ;; 3.7 Description styles ("style" ("standard" "unboxed" "nextline" "sameline" "multiline")) ;; 3.8 Compact lists ("noitemsep") ("nosep") ;; 3.9 Wide lists ("wide") ;; 4 Inline lists ("itemjoin") ("itemjoin*") ("afterlabel") ("mode" ("boxed" "unboxed"))) "Key=value options for enumitem macros and environments.") (defun LaTeX-enumitem-key-val-options () "Return an updated list of key=vals from enumitem package." (append ;; New keys are valueless, so take them as is: (when (LaTeX-enumitem-SetEnumitemKey-list) (LaTeX-enumitem-SetEnumitemKey-list)) ;; New values defined available keys: We have to collect predefined ;; values (if any) from `LaTeX-enumitem-key-val-options' (stored in ;; `vals-predefined') and user-defined values (stored in ;; `vals-parsed') which were parsed and added to `result' in the ;; previous run of `dolist' and then combine them as value to a ;; key. (when (LaTeX-enumitem-SetEnumitemValue-list) (let (result) (dolist (keyvals (LaTeX-enumitem-SetEnumitemValue-list) result) (let* ((key (nth 1 keyvals)) (val (nth 2 keyvals)) (vals-predefined (cadr (assoc key LaTeX-enumitem-key-val-options))) (vals-parsed (cadr (assoc key result)))) ;; Remove entry in `result' if there is one for the `key': (when (assoc key result) (setq result (assq-delete-all (car (assoc key result)) result))) ;; Add the entry to `result'; also remove any duplicates (cl-pushnew (list key (TeX-delete-duplicate-strings (append vals-parsed vals-predefined (list val)))) result :test #'equal))))) ;; New values to `align' key: We collect the predefined ones from ;; `LaTeX-enumitem-key-val-options' in `vals-predefined' and ;; prepend them to newly parsed ones: (when (LaTeX-enumitem-SetLabelAlign-list) (let* ((key "align") (vals (mapcar #'car (LaTeX-enumitem-SetLabelAlign-list))) (vals-predefined (cadr (assoc key LaTeX-enumitem-key-val-options)))) `(("align" ,(TeX-delete-duplicate-strings (append vals-predefined vals)))))) ;; Predefined key=vals: LaTeX-enumitem-key-val-options)) ;; Setup for \newlist: (TeX-auto-add-type "enumitem-newlist" "LaTeX") (defvar LaTeX-enumitem-newlist-regexp '("\\\\newlist{\\([^}]+\\)}{\\([^}]+\\)}" (1 2) LaTeX-auto-enumitem-newlist) "Matches the arguments of `\\newlist' from `enumitem' package.") ;; Setup for \SetLabelAlign: (TeX-auto-add-type "enumitem-SetLabelAlign" "LaTeX") (defvar LaTeX-enumitem-SetLabelAlign-regexp '("\\\\SetLabelAlign{\\([^}]+\\)}" 1 LaTeX-auto-enumitem-SetLabelAlign) "Matches the argument of `\\SetLabelAlign' from `enumitem' package.") ;; Setup for \SetEnumitemKey: (TeX-auto-add-type "enumitem-SetEnumitemKey" "LaTeX") (defvar LaTeX-enumitem-SetEnumitemKey-regexp '("\\\\SetEnumitemKey{\\([^}]+\\)}" 1 LaTeX-auto-enumitem-SetEnumitemKey) "Matches the arguments of `\\SetEnumitemKey' from `enumitem' package.") ;; Setup for \SetEnumitemValue: (TeX-auto-add-type "enumitem-SetEnumitemValue" "LaTeX") ;; Upon Tassilo's recommendation, we include also `0' so that we can ;; use the function `LaTeX-enumitem-SetEnumitemValue-list' while we ;; make sure that `TeX-auto-list-information' doesn't remove multiple ;; defined values to a specific key. For this reason, we also ignore ;; the 3. argument to the `\SetEnumitemValue' macro (i.e., a third ;; {\\([^}]+\\)} in regex) so that we don't pollute the generated ;; `docname.el' with unnecessary (La)TeX code. (defvar LaTeX-enumitem-SetEnumitemValue-regexp '("\\\\SetEnumitemValue{\\([^}]+\\)}{\\([^}]+\\)}" (0 1 2) LaTeX-auto-enumitem-SetEnumitemValue) "Matches the arguments of `\\SetEnumitemValue' from `enumitem' package.") ;; Plug them into the machinery. (defun LaTeX-enumitem-auto-prepare () "Clear various `LaTeX-enumitem-*' before parsing." (setq LaTeX-auto-enumitem-newlist nil LaTeX-auto-enumitem-SetLabelAlign nil LaTeX-auto-enumitem-SetEnumitemKey nil LaTeX-auto-enumitem-SetEnumitemValue nil)) (defun LaTeX-enumitem-auto-cleanup () "Move parsing results into right places for further usage." ;; \newlist{<name>}{<type>}{<max-depth>} ;; env=<name>, type=<type>, ignored=<max-depth> (dolist (env-type (LaTeX-enumitem-newlist-list)) (let* ((env (car env-type)) (type (cadr env-type))) (LaTeX-add-environments (list env 'LaTeX-enumitem-env-with-opts)) ;; Tell AUCTeX about parsed description like environments. (when (or (string-equal type "description") (string-equal type "description*")) (add-to-list 'LaTeX-item-list `(,env . LaTeX-item-argument))) ;; Add new env's to `ispell-tex-skip-alist': skip the opt. arg: (TeX-ispell-skip-setcdr `((,env ispell-tex-arg-end 0)))))) (add-hook 'TeX-auto-prepare-hook #'LaTeX-enumitem-auto-prepare t) (add-hook 'TeX-auto-cleanup-hook #'LaTeX-enumitem-auto-cleanup t) (add-hook 'TeX-update-style-hook #'TeX-auto-parse t) (defun LaTeX-enumitem-env-with-opts (env) "Insert ENV provided by `enumitem' package." (LaTeX-insert-environment env (let ((opts (TeX-read-key-val t (LaTeX-enumitem-key-val-options)))) (when (and opts (not (string-equal opts ""))) (format "[%s]" opts)))) (if (TeX-active-mark) (progn (LaTeX-find-matching-begin) (end-of-line 1)) (end-of-line 0)) (delete-char 1) (when (looking-at (concat "^[ \t]+$\\|" "^[ \t]*" TeX-comment-start-regexp "+[ \t]*$")) (delete-region (point) (line-end-position))) (delete-horizontal-space) ;; Deactivate the mark here in order to prevent `TeX-parse-macro' ;; from swapping point and mark and the \item ending up right after ;; \begin{...}. (deactivate-mark) (LaTeX-insert-item) ;; The inserted \item may have outdented the first line to the ;; right. Fill it, if appropriate. (when (and auto-fill-function (not (looking-at "$")) (not (assoc env LaTeX-indent-environment-list)) (> (- (line-end-position) (line-beginning-position)) (current-fill-column))) (LaTeX-fill-paragraph nil))) (defun LaTeX-arg-enumitem-SetLabelAlign (optional) "Ask and insert a new type (value) for the \"align\" key. Insert value in brackets if OPTIONAL is non-nil." (let ((val (TeX-read-string "Alignment: "))) (TeX-argument-insert val optional) (LaTeX-add-enumitem-SetLabelAligns val))) (defun LaTeX-arg-enumitem-SetEnumitemKey (optional) "Ask and insert a new key and its replacement. Insert key and value in brackets if OPTIONAL is non-nil." (let ((key (TeX-read-string "New Key: ")) (replace (TeX-read-key-val optional (LaTeX-enumitem-key-val-options) "Replacement"))) (TeX-argument-insert key optional) (TeX-argument-insert replace optional) (LaTeX-add-enumitem-SetEnumitemKeys key))) ;; In `LaTeX-enumitem-SetEnumitemValue-regexp', we match (0 1 2). ;; When adding a new `key=val', we need something unique for `0'-match ;; until the next `C-c C-n'. We mimic that regex-match bei concat'ing ;; the elements and pass the result to ;; `LaTeX-add-enumitem-SetEnumitemValues'. It will vanish upon next ;; invocation of `C-c C-n'. (defun LaTeX-arg-enumitem-SetEnumitemValue (optional) "Ask and insert for a new value added to an existing key. Insert key and value in brackets if OPTIONAL is non-nil." (let ((key (completing-read "Key: " LaTeX-enumitem-key-val-options)) (val (TeX-read-string "String value: "))) (TeX-argument-insert key optional) (TeX-argument-insert val optional) (LaTeX-add-enumitem-SetEnumitemValues (list (concat "\\SetEnumitemValue{" key "}{" val "}") key val)))) (defun LaTeX-arg-enumitem-setlist (_optional) "Insert the arguments of `\\setlist' macro from `enumitem' package. This function inserts three arguments. The first optional argument is only available when the package option `sizes' is provided. OPTIONAL is ignored." ;; First opt. argument: (when (LaTeX-provided-package-options-member "enumitem" "sizes") (let* ((TeX-arg-opening-brace "<") (TeX-arg-closing-brace ">") (sizes '("script" "tiny" "footnote" "small" "normal" "large" "Large" "LARGE" "huge" "Huge")) (size (completing-read (TeX-argument-prompt t nil "Size") (append (mapcar (lambda (x) (concat "-" x)) sizes) (mapcar (lambda (x) (concat x "-")) sizes) sizes)))) (TeX-argument-insert size t))) ;; Second opt. argument: (TeX-argument-insert (mapconcat #'identity (TeX-completing-read-multiple (TeX-argument-prompt t nil "Environment(s), level(s)") (append (when (LaTeX-provided-package-options-member "enumitem" "includedisplayed") '("trivlist")) (mapcar #'car (LaTeX-enumitem-newlist-list)) '("1" "2" "3" "4"))) ",") t) ;; Mandatory argument: (TeX-argument-insert (TeX-read-key-val nil (LaTeX-enumitem-key-val-options)) nil)) (TeX-add-style-hook "enumitem" (lambda () ;; Add enumitem to the parser. (TeX-auto-add-regexp LaTeX-enumitem-newlist-regexp) (TeX-auto-add-regexp LaTeX-enumitem-SetEnumitemKey-regexp) (TeX-auto-add-regexp LaTeX-enumitem-SetEnumitemValue-regexp) (TeX-auto-add-regexp LaTeX-enumitem-SetLabelAlign-regexp) ;; Add the standard environments: (LaTeX-add-enumitem-newlists '("itemize" "itemize") '("enumerate" "enumerate") '("description" "description")) ;; Add the starred versions with the 'inline' package option: (when (LaTeX-provided-package-options-member "enumitem" "inline") (LaTeX-add-enumitem-newlists '("itemize*" "itemize*") '("enumerate*" "enumerate*") '("description*" "description*"))) ;; Standard env's take key-val as optional argument. (LaTeX-add-environments '("itemize" LaTeX-enumitem-env-with-opts) '("enumerate" LaTeX-enumitem-env-with-opts) '("description" LaTeX-enumitem-env-with-opts)) ;; Make inline env's available with package option "inline" (when (LaTeX-provided-package-options-member "enumitem" "inline") (LaTeX-add-environments '("itemize*" LaTeX-enumitem-env-with-opts) '("enumerate*" LaTeX-enumitem-env-with-opts) '("description*" LaTeX-enumitem-env-with-opts)) (add-to-list 'LaTeX-item-list '("description*" . LaTeX-item-argument))) (TeX-add-symbols ;; 6 Size dependent settings '("SetEnumitemSize" 2) ;; 7 Cloning the basic lists ;; The easy way would be: ;; '("newlist" ;; "Name" (TeX-arg-eval ;; completing-read "Type: " ;; '(("itemize") ("enumerate") ("description") ;; ("itemize*") ("enumerate*") ("description*"))) ;; "Max-depth") ;; But we go the extra mile to improve the user experience and add ;; the arguments directly to appropriate lists. ;; \newlist{<name>}{<type>}{<max-depth>} '("newlist" (TeX-arg-eval (lambda () (let ((name (TeX-read-string "Name: ")) (type (completing-read "Type: " (mapcar #'cadr (LaTeX-enumitem-newlist-list)))) (depth (TeX-read-string "Max-depth: "))) (when (or (string-equal type "description") (string-equal type "description*")) (add-to-list 'LaTeX-item-list `(,name . LaTeX-item-argument))) (LaTeX-add-environments `(,name LaTeX-enumitem-env-with-opts)) (LaTeX-add-enumitem-newlists (list name type)) (TeX-ispell-skip-setcdr `((,name ispell-tex-arg-end 0))) (TeX-argument-insert name nil) (TeX-argument-insert type nil) (format "%s" depth))))) ;; \renewlist{<name>}{<type>}{<max-depth>} '("renewlist" (TeX-arg-eval completing-read "Name: " (mapcar #'car (LaTeX-enumitem-newlist-list))) (TeX-arg-eval completing-read "Type: " (mapcar #'cadr (LaTeX-enumitem-newlist-list))) "Max-depth") ;; \setlist<size>[<names,levels>]{<key-vals>} '("setlist" LaTeX-arg-enumitem-setlist) ;; \setlist*[<names,levels>]{<key-vals>} '("setlist*" [TeX-arg-eval mapconcat #'identity (TeX-completing-read-multiple (TeX-argument-prompt t nil "Environment(s), level(s)") (append (when (LaTeX-provided-package-options-member "enumitem" "includedisplayed") '("trivlist")) (mapcar #'car (LaTeX-enumitem-newlist-list)) '("1" "2" "3" "4"))) ","] (TeX-arg-key-val (LaTeX-enumitem-key-val-options))) ) ;; General commands: (TeX-add-symbols ;; Ask for an Integer and insert it. '("setlistdepth" "Integer") ;; Just add the braces and let the user do the rest. '("AddEnumerateCounter" 3) '("AddEnumerateCounter*" 3) ;; "\restartlist" only works for lists defined with "resume" key. ;; We will not extract that information and leave that to users. ;; For completion, extract enumerated environments from ;; `LaTeX-enumitem-newlist-list' and add "enumerate" to them. '("restartlist" (TeX-arg-eval (lambda () (let ((enums '("enumerate"))) (when (LaTeX-provided-package-options-member "enumitem" "inline") (cl-pushnew "enumerate*" enums :test #'equal)) (dolist (env-type (LaTeX-enumitem-newlist-list)) (let ((env (car env-type)) (type (cadr env-type))) (when (or (string-equal type "enumerate") (string-equal type "enumerate*")) (cl-pushnew env enums :test #'equal)))) (completing-read "List name: " enums))))) ;; "Align" is added as new value to "align" key in key-val list. '("SetLabelAlign" LaTeX-arg-enumitem-SetLabelAlign t) ;; "Key" will be parsed and added to key-val list. '("SetEnumitemKey" LaTeX-arg-enumitem-SetEnumitemKey) ;; "Key" and "Value" are added to our key-val list. '("SetEnumitemValue" LaTeX-arg-enumitem-SetEnumitemValue "Replacement") ;; v3.6 has a macro for visual debugging. '("DrawEnumitemLabel" 0)) ;; Setting enumerate short label (when (LaTeX-provided-package-options-member "enumitem" "shortlabels") (TeX-add-symbols '("SetEnumerateShortLabel" (TeX-arg-eval completing-read "Key: " '("A" "a" "I" "i" "1")) "Replacement"))) ;; Add \labelindent to list of known lengths: (LaTeX-add-lengths "labelindent") ;; Fontification (when (and (featurep 'font-latex) (eq TeX-install-font-lock 'font-latex-setup)) (font-latex-add-keywords '(("newlist" "{{{") ("renewlist" "{{{") ("SetEnumitemSize" "{{") ("AddEnumerateCounter" "*{{{") ("SetLabelAlign" "{{") ("SetEnumitemKey" "{{" ) ("SetEnumitemValue" "{{{")) 'function) ;; Cater for additional optionals arg <size> based on package ;; option 'sizes': (font-latex-add-keywords (if (LaTeX-provided-package-options-member "enumitem" "sizes") '(("setlist" "*<[{")) '(("setlist" "*[{"))) 'function) (font-latex-add-keywords '(("restartlist" "{" ) ("setlistdepth" "{" ) ("SetEnumerateShortLabel" "{{")) 'variable))) TeX-dialect) (defvar LaTeX-enumitem-package-options '("inline" "shortlabels" "loadonly" "sizes" "ignoredisplayed" "includedisplayed") "Package options for the enumitem package.") ;;; enumitem.el ends here
43755
;;; enumitem.el --- AUCTeX style for `enumitem.sty' (v3.9) -*- lexical-binding: t; -*- ;; Copyright (C) 2015--2021 Free Software Foundation, Inc. ;; Author: <NAME> <<EMAIL>> ;; Maintainer: <EMAIL> ;; Created: 2014-10-20 ;; Keywords: tex ;; This file is part of AUCTeX. ;; AUCTeX 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, or (at your option) ;; any later version. ;; AUCTeX 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 AUCTeX; see the file COPYING. If not, write to the Free ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA ;; 02110-1301, USA. ;;; Commentary: ;; This file adds support for `enumitem.sty' (v3.9) from 2019/06/20. ;; `enumitem.sty' is part of TeXLive. ;; Tassilo Horn's `minted.el' was a major source of inspiration for ;; this style, many thanks to him (also for patiently answering my ;; many other questions, incl. the stupid ones.) ;; If things do not work or when in doubt, press `C-c C-n'. Comments ;; for improvement are welcome. ;;; Code: (require 'tex) (require 'latex) (eval-when-compile (require 'cl-lib)) ;; Silence the compiler: (declare-function font-latex-add-keywords "font-latex" (keywords class)) (defvar LaTeX-enumitem-key-val-options `(;; 3.1 Label and cross references format ("label" ("\\alph*" "\\Alph*" "\\arabic*" "\\roman*" "\\Roman*" "\\value*")) ("label*" ("\\alph*" "\\Alph*" "\\arabic*" "\\roman*" "\\Roman*" "\\value*")) ("ref" ("\\alph*" "\\Alph*" "\\arabic*" "\\roman*" "\\Roman*" "\\value*")) ("font" ,(mapcar (lambda (mac) (concat TeX-esc mac)) '(;; family "rmfamily" "sffamily" "ttfamily" ;; series "mdseries" "bfseries" ;; shape "upshape" "itshape" "slshape" "scshape" ;; size "tiny" "scriptsize" "footnotesize" "small" "normalsize" "large" "Large" "LARGE" "huge" "Huge" ;; reset macro "normalfont"))) ("format" ,(mapcar (lambda (mac) (concat TeX-esc mac)) '(;; family "rmfamily" "sffamily" "ttfamily" ;; series "mdseries" "bfseries" ;; shape "upshape" "itshape" "slshape" "scshape" ;; size "tiny" "scriptsize" "footnotesize" "small" "normalsize" "large" "Large" "LARGE" "huge" "Huge" ;; reset macro "normalfont"))) ("align" ("left" "right" "parleft")) ;; 3.2 Horizontal spacing of labels ("labelindent" ("*" "!")) ("left") ("leftmargin" ("*" "!")) ("itemindent" ("*" "!")) ("labelsep" ("*" "!")) ("labelwidth" ("*" "!")) ("widest") ("widest*") ("labelsep*") ("labelindent*") ("rightmargin") ;; Vertical Spacing ("topsep") ("partopsep") ("parsep") ("itemsep") ;; 3.3 Numbering, stopping, and resuming ("start") ("resume") ("resume*") ;; 3.4 Series ("series") ;; 3.5 Penalties ("beginpenalty") ("midpenalty") ("endpenalty") ;; 3.6 Injecting code ("before") ("before*") ("after") ("after*") ("first") ("first*") ;; 3.7 Description styles ("style" ("standard" "unboxed" "nextline" "sameline" "multiline")) ;; 3.8 Compact lists ("noitemsep") ("nosep") ;; 3.9 Wide lists ("wide") ;; 4 Inline lists ("itemjoin") ("itemjoin*") ("afterlabel") ("mode" ("boxed" "unboxed"))) "Key=value options for enumitem macros and environments.") (defun LaTeX-enumitem-key-val-options () "Return an updated list of key=vals from enumitem package." (append ;; New keys are valueless, so take them as is: (when (LaTeX-enumitem-SetEnumitemKey-list) (LaTeX-enumitem-SetEnumitemKey-list)) ;; New values defined available keys: We have to collect predefined ;; values (if any) from `LaTeX-enumitem-key-val-options' (stored in ;; `vals-predefined') and user-defined values (stored in ;; `vals-parsed') which were parsed and added to `result' in the ;; previous run of `dolist' and then combine them as value to a ;; key. (when (LaTeX-enumitem-SetEnumitemValue-list) (let (result) (dolist (keyvals (LaTeX-enumitem-SetEnumitemValue-list) result) (let* ((key (nth 1 keyvals)) (val (nth 2 keyvals)) (vals-predefined (cadr (assoc key LaTeX-enumitem-key-val-options))) (vals-parsed (cadr (assoc key result)))) ;; Remove entry in `result' if there is one for the `key': (when (assoc key result) (setq result (assq-delete-all (car (assoc key result)) result))) ;; Add the entry to `result'; also remove any duplicates (cl-pushnew (list key (TeX-delete-duplicate-strings (append vals-parsed vals-predefined (list val)))) result :test #'equal))))) ;; New values to `align' key: We collect the predefined ones from ;; `LaTeX-enumitem-key-val-options' in `vals-predefined' and ;; prepend them to newly parsed ones: (when (LaTeX-enumitem-SetLabelAlign-list) (let* ((key "<KEY>") (vals (mapcar #'car (LaTeX-enumitem-SetLabelAlign-list))) (vals-predefined (cadr (assoc key LaTeX-enumitem-key-val-options)))) `(("align" ,(TeX-delete-duplicate-strings (append vals-predefined vals)))))) ;; Predefined key=vals: LaTeX-enumitem-key-val-options)) ;; Setup for \newlist: (TeX-auto-add-type "enumitem-newlist" "LaTeX") (defvar LaTeX-enumitem-newlist-regexp '("\\\\newlist{\\([^}]+\\)}{\\([^}]+\\)}" (1 2) LaTeX-auto-enumitem-newlist) "Matches the arguments of `\\newlist' from `enumitem' package.") ;; Setup for \SetLabelAlign: (TeX-auto-add-type "enumitem-SetLabelAlign" "LaTeX") (defvar LaTeX-enumitem-SetLabelAlign-regexp '("\\\\SetLabelAlign{\\([^}]+\\)}" 1 LaTeX-auto-enumitem-SetLabelAlign) "Matches the argument of `\\SetLabelAlign' from `enumitem' package.") ;; Setup for \SetEnumitemKey: (TeX-auto-add-type "enumitem-SetEnumitemKey" "LaTeX") (defvar LaTeX-enumitem-SetEnumitemKey-regexp '("\\\\SetEnumitemKey{\\([^}]+\\)}" 1 LaTeX-auto-enumitem-SetEnumitemKey) "Matches the arguments of `\\SetEnumitemKey' from `enumitem' package.") ;; Setup for \SetEnumitemValue: (TeX-auto-add-type "enumitem-SetEnumitemValue" "LaTeX") ;; Upon Tassilo's recommendation, we include also `0' so that we can ;; use the function `LaTeX-enumitem-SetEnumitemValue-list' while we ;; make sure that `TeX-auto-list-information' doesn't remove multiple ;; defined values to a specific key. For this reason, we also ignore ;; the 3. argument to the `\SetEnumitemValue' macro (i.e., a third ;; {\\([^}]+\\)} in regex) so that we don't pollute the generated ;; `docname.el' with unnecessary (La)TeX code. (defvar LaTeX-enumitem-SetEnumitemValue-regexp '("\\\\SetEnumitemValue{\\([^}]+\\)}{\\([^}]+\\)}" (0 1 2) LaTeX-auto-enumitem-SetEnumitemValue) "Matches the arguments of `\\SetEnumitemValue' from `enumitem' package.") ;; Plug them into the machinery. (defun LaTeX-enumitem-auto-prepare () "Clear various `LaTeX-enumitem-*' before parsing." (setq LaTeX-auto-enumitem-newlist nil LaTeX-auto-enumitem-SetLabelAlign nil LaTeX-auto-enumitem-SetEnumitemKey nil LaTeX-auto-enumitem-SetEnumitemValue nil)) (defun LaTeX-enumitem-auto-cleanup () "Move parsing results into right places for further usage." ;; \newlist{<name>}{<type>}{<max-depth>} ;; env=<name>, type=<type>, ignored=<max-depth> (dolist (env-type (LaTeX-enumitem-newlist-list)) (let* ((env (car env-type)) (type (cadr env-type))) (LaTeX-add-environments (list env 'LaTeX-enumitem-env-with-opts)) ;; Tell AUCTeX about parsed description like environments. (when (or (string-equal type "description") (string-equal type "description*")) (add-to-list 'LaTeX-item-list `(,env . LaTeX-item-argument))) ;; Add new env's to `ispell-tex-skip-alist': skip the opt. arg: (TeX-ispell-skip-setcdr `((,env ispell-tex-arg-end 0)))))) (add-hook 'TeX-auto-prepare-hook #'LaTeX-enumitem-auto-prepare t) (add-hook 'TeX-auto-cleanup-hook #'LaTeX-enumitem-auto-cleanup t) (add-hook 'TeX-update-style-hook #'TeX-auto-parse t) (defun LaTeX-enumitem-env-with-opts (env) "Insert ENV provided by `enumitem' package." (LaTeX-insert-environment env (let ((opts (TeX-read-key-val t (LaTeX-enumitem-key-val-options)))) (when (and opts (not (string-equal opts ""))) (format "[%s]" opts)))) (if (TeX-active-mark) (progn (LaTeX-find-matching-begin) (end-of-line 1)) (end-of-line 0)) (delete-char 1) (when (looking-at (concat "^[ \t]+$\\|" "^[ \t]*" TeX-comment-start-regexp "+[ \t]*$")) (delete-region (point) (line-end-position))) (delete-horizontal-space) ;; Deactivate the mark here in order to prevent `TeX-parse-macro' ;; from swapping point and mark and the \item ending up right after ;; \begin{...}. (deactivate-mark) (LaTeX-insert-item) ;; The inserted \item may have outdented the first line to the ;; right. Fill it, if appropriate. (when (and auto-fill-function (not (looking-at "$")) (not (assoc env LaTeX-indent-environment-list)) (> (- (line-end-position) (line-beginning-position)) (current-fill-column))) (LaTeX-fill-paragraph nil))) (defun LaTeX-arg-enumitem-SetLabelAlign (optional) "Ask and insert a new type (value) for the \"align\" key. Insert value in brackets if OPTIONAL is non-nil." (let ((val (TeX-read-string "Alignment: "))) (TeX-argument-insert val optional) (LaTeX-add-enumitem-SetLabelAligns val))) (defun LaTeX-arg-enumitem-SetEnumitemKey (optional) "Ask and insert a new key and its replacement. Insert key and value in brackets if OPTIONAL is non-nil." (let ((key (TeX-read-string "New Key: ")) (replace (TeX-read-key-val optional (LaTeX-enumitem-key-val-options) "Replacement"))) (TeX-argument-insert key optional) (TeX-argument-insert replace optional) (LaTeX-add-enumitem-SetEnumitemKeys key))) ;; In `LaTeX-enumitem-SetEnumitemValue-regexp', we match (0 1 2). ;; When adding a new `key=val', we need something unique for `0'-match ;; until the next `C-c C-n'. We mimic that regex-match bei concat'ing ;; the elements and pass the result to ;; `LaTeX-add-enumitem-SetEnumitemValues'. It will vanish upon next ;; invocation of `C-c C-n'. (defun LaTeX-arg-enumitem-SetEnumitemValue (optional) "Ask and insert for a new value added to an existing key. Insert key and value in brackets if OPTIONAL is non-nil." (let ((key (completing-read "Key: " LaTeX-enumitem-key-val-options)) (val (TeX-read-string "String value: "))) (TeX-argument-insert key optional) (TeX-argument-insert val optional) (LaTeX-add-enumitem-SetEnumitemValues (list (concat "\\SetEnumitemValue{" key "}{" val "}") key val)))) (defun LaTeX-arg-enumitem-setlist (_optional) "Insert the arguments of `\\setlist' macro from `enumitem' package. This function inserts three arguments. The first optional argument is only available when the package option `sizes' is provided. OPTIONAL is ignored." ;; First opt. argument: (when (LaTeX-provided-package-options-member "enumitem" "sizes") (let* ((TeX-arg-opening-brace "<") (TeX-arg-closing-brace ">") (sizes '("script" "tiny" "footnote" "small" "normal" "large" "Large" "LARGE" "huge" "Huge")) (size (completing-read (TeX-argument-prompt t nil "Size") (append (mapcar (lambda (x) (concat "-" x)) sizes) (mapcar (lambda (x) (concat x "-")) sizes) sizes)))) (TeX-argument-insert size t))) ;; Second opt. argument: (TeX-argument-insert (mapconcat #'identity (TeX-completing-read-multiple (TeX-argument-prompt t nil "Environment(s), level(s)") (append (when (LaTeX-provided-package-options-member "enumitem" "includedisplayed") '("trivlist")) (mapcar #'car (LaTeX-enumitem-newlist-list)) '("1" "2" "3" "4"))) ",") t) ;; Mandatory argument: (TeX-argument-insert (TeX-read-key-val nil (LaTeX-enumitem-key-val-options)) nil)) (TeX-add-style-hook "enumitem" (lambda () ;; Add enumitem to the parser. (TeX-auto-add-regexp LaTeX-enumitem-newlist-regexp) (TeX-auto-add-regexp LaTeX-enumitem-SetEnumitemKey-regexp) (TeX-auto-add-regexp LaTeX-enumitem-SetEnumitemValue-regexp) (TeX-auto-add-regexp LaTeX-enumitem-SetLabelAlign-regexp) ;; Add the standard environments: (LaTeX-add-enumitem-newlists '("itemize" "itemize") '("enumerate" "enumerate") '("description" "description")) ;; Add the starred versions with the 'inline' package option: (when (LaTeX-provided-package-options-member "enumitem" "inline") (LaTeX-add-enumitem-newlists '("itemize*" "itemize*") '("enumerate*" "enumerate*") '("description*" "description*"))) ;; Standard env's take key-val as optional argument. (LaTeX-add-environments '("itemize" LaTeX-enumitem-env-with-opts) '("enumerate" LaTeX-enumitem-env-with-opts) '("description" LaTeX-enumitem-env-with-opts)) ;; Make inline env's available with package option "inline" (when (LaTeX-provided-package-options-member "enumitem" "inline") (LaTeX-add-environments '("itemize*" LaTeX-enumitem-env-with-opts) '("enumerate*" LaTeX-enumitem-env-with-opts) '("description*" LaTeX-enumitem-env-with-opts)) (add-to-list 'LaTeX-item-list '("description*" . LaTeX-item-argument))) (TeX-add-symbols ;; 6 Size dependent settings '("SetEnumitemSize" 2) ;; 7 Cloning the basic lists ;; The easy way would be: ;; '("newlist" ;; "Name" (TeX-arg-eval ;; completing-read "Type: " ;; '(("itemize") ("enumerate") ("description") ;; ("itemize*") ("enumerate*") ("description*"))) ;; "Max-depth") ;; But we go the extra mile to improve the user experience and add ;; the arguments directly to appropriate lists. ;; \newlist{<name>}{<type>}{<max-depth>} '("newlist" (TeX-arg-eval (lambda () (let ((name (TeX-read-string "Name: ")) (type (completing-read "Type: " (mapcar #'cadr (LaTeX-enumitem-newlist-list)))) (depth (TeX-read-string "Max-depth: "))) (when (or (string-equal type "description") (string-equal type "description*")) (add-to-list 'LaTeX-item-list `(,name . LaTeX-item-argument))) (LaTeX-add-environments `(,name LaTeX-enumitem-env-with-opts)) (LaTeX-add-enumitem-newlists (list name type)) (TeX-ispell-skip-setcdr `((,name ispell-tex-arg-end 0))) (TeX-argument-insert name nil) (TeX-argument-insert type nil) (format "%s" depth))))) ;; \renewlist{<name>}{<type>}{<max-depth>} '("renewlist" (TeX-arg-eval completing-read "Name: " (mapcar #'car (LaTeX-enumitem-newlist-list))) (TeX-arg-eval completing-read "Type: " (mapcar #'cadr (LaTeX-enumitem-newlist-list))) "Max-depth") ;; \setlist<size>[<names,levels>]{<key-vals>} '("setlist" LaTeX-arg-enumitem-setlist) ;; \setlist*[<names,levels>]{<key-vals>} '("setlist*" [TeX-arg-eval mapconcat #'identity (TeX-completing-read-multiple (TeX-argument-prompt t nil "Environment(s), level(s)") (append (when (LaTeX-provided-package-options-member "enumitem" "includedisplayed") '("trivlist")) (mapcar #'car (LaTeX-enumitem-newlist-list)) '("1" "2" "3" "4"))) ","] (TeX-arg-key-val (LaTeX-enumitem-key-val-options))) ) ;; General commands: (TeX-add-symbols ;; Ask for an Integer and insert it. '("setlistdepth" "Integer") ;; Just add the braces and let the user do the rest. '("AddEnumerateCounter" 3) '("AddEnumerateCounter*" 3) ;; "\restartlist" only works for lists defined with "resume" key. ;; We will not extract that information and leave that to users. ;; For completion, extract enumerated environments from ;; `LaTeX-enumitem-newlist-list' and add "enumerate" to them. '("restartlist" (TeX-arg-eval (lambda () (let ((enums '("enumerate"))) (when (LaTeX-provided-package-options-member "enumitem" "inline") (cl-pushnew "enumerate*" enums :test #'equal)) (dolist (env-type (LaTeX-enumitem-newlist-list)) (let ((env (car env-type)) (type (cadr env-type))) (when (or (string-equal type "enumerate") (string-equal type "enumerate*")) (cl-pushnew env enums :test #'equal)))) (completing-read "List name: " enums))))) ;; "Align" is added as new value to "align" key in key-val list. '("SetLabelAlign" LaTeX-arg-enumitem-SetLabelAlign t) ;; "Key" will be parsed and added to key-val list. '("SetEnumitemKey" LaTeX-arg-enumitem-SetEnumitemKey) ;; "Key" and "Value" are added to our key-val list. '("SetEnumitemValue" LaTeX-arg-enumitem-SetEnumitemValue "Replacement") ;; v3.6 has a macro for visual debugging. '("DrawEnumitemLabel" 0)) ;; Setting enumerate short label (when (LaTeX-provided-package-options-member "enumitem" "shortlabels") (TeX-add-symbols '("SetEnumerateShortLabel" (TeX-arg-eval completing-read "Key: " '("A" "a" "I" "i" "1")) "Replacement"))) ;; Add \labelindent to list of known lengths: (LaTeX-add-lengths "labelindent") ;; Fontification (when (and (featurep 'font-latex) (eq TeX-install-font-lock 'font-latex-setup)) (font-latex-add-keywords '(("newlist" "{{{") ("renewlist" "{{{") ("SetEnumitemSize" "{{") ("AddEnumerateCounter" "*{{{") ("SetLabelAlign" "{{") ("SetEnumitemKey" "{{" ) ("SetEnumitemValue" "{{{")) 'function) ;; Cater for additional optionals arg <size> based on package ;; option 'sizes': (font-latex-add-keywords (if (LaTeX-provided-package-options-member "enumitem" "sizes") '(("setlist" "*<[{")) '(("setlist" "*[{"))) 'function) (font-latex-add-keywords '(("restartlist" "{" ) ("setlistdepth" "{" ) ("SetEnumerateShortLabel" "{{")) 'variable))) TeX-dialect) (defvar LaTeX-enumitem-package-options '("inline" "shortlabels" "loadonly" "sizes" "ignoredisplayed" "includedisplayed") "Package options for the enumitem package.") ;;; enumitem.el ends here
true
;;; enumitem.el --- AUCTeX style for `enumitem.sty' (v3.9) -*- lexical-binding: t; -*- ;; Copyright (C) 2015--2021 Free Software Foundation, Inc. ;; Author: PI:NAME:<NAME>END_PI <PI:EMAIL:<EMAIL>END_PI> ;; Maintainer: PI:EMAIL:<EMAIL>END_PI ;; Created: 2014-10-20 ;; Keywords: tex ;; This file is part of AUCTeX. ;; AUCTeX 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, or (at your option) ;; any later version. ;; AUCTeX 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 AUCTeX; see the file COPYING. If not, write to the Free ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA ;; 02110-1301, USA. ;;; Commentary: ;; This file adds support for `enumitem.sty' (v3.9) from 2019/06/20. ;; `enumitem.sty' is part of TeXLive. ;; Tassilo Horn's `minted.el' was a major source of inspiration for ;; this style, many thanks to him (also for patiently answering my ;; many other questions, incl. the stupid ones.) ;; If things do not work or when in doubt, press `C-c C-n'. Comments ;; for improvement are welcome. ;;; Code: (require 'tex) (require 'latex) (eval-when-compile (require 'cl-lib)) ;; Silence the compiler: (declare-function font-latex-add-keywords "font-latex" (keywords class)) (defvar LaTeX-enumitem-key-val-options `(;; 3.1 Label and cross references format ("label" ("\\alph*" "\\Alph*" "\\arabic*" "\\roman*" "\\Roman*" "\\value*")) ("label*" ("\\alph*" "\\Alph*" "\\arabic*" "\\roman*" "\\Roman*" "\\value*")) ("ref" ("\\alph*" "\\Alph*" "\\arabic*" "\\roman*" "\\Roman*" "\\value*")) ("font" ,(mapcar (lambda (mac) (concat TeX-esc mac)) '(;; family "rmfamily" "sffamily" "ttfamily" ;; series "mdseries" "bfseries" ;; shape "upshape" "itshape" "slshape" "scshape" ;; size "tiny" "scriptsize" "footnotesize" "small" "normalsize" "large" "Large" "LARGE" "huge" "Huge" ;; reset macro "normalfont"))) ("format" ,(mapcar (lambda (mac) (concat TeX-esc mac)) '(;; family "rmfamily" "sffamily" "ttfamily" ;; series "mdseries" "bfseries" ;; shape "upshape" "itshape" "slshape" "scshape" ;; size "tiny" "scriptsize" "footnotesize" "small" "normalsize" "large" "Large" "LARGE" "huge" "Huge" ;; reset macro "normalfont"))) ("align" ("left" "right" "parleft")) ;; 3.2 Horizontal spacing of labels ("labelindent" ("*" "!")) ("left") ("leftmargin" ("*" "!")) ("itemindent" ("*" "!")) ("labelsep" ("*" "!")) ("labelwidth" ("*" "!")) ("widest") ("widest*") ("labelsep*") ("labelindent*") ("rightmargin") ;; Vertical Spacing ("topsep") ("partopsep") ("parsep") ("itemsep") ;; 3.3 Numbering, stopping, and resuming ("start") ("resume") ("resume*") ;; 3.4 Series ("series") ;; 3.5 Penalties ("beginpenalty") ("midpenalty") ("endpenalty") ;; 3.6 Injecting code ("before") ("before*") ("after") ("after*") ("first") ("first*") ;; 3.7 Description styles ("style" ("standard" "unboxed" "nextline" "sameline" "multiline")) ;; 3.8 Compact lists ("noitemsep") ("nosep") ;; 3.9 Wide lists ("wide") ;; 4 Inline lists ("itemjoin") ("itemjoin*") ("afterlabel") ("mode" ("boxed" "unboxed"))) "Key=value options for enumitem macros and environments.") (defun LaTeX-enumitem-key-val-options () "Return an updated list of key=vals from enumitem package." (append ;; New keys are valueless, so take them as is: (when (LaTeX-enumitem-SetEnumitemKey-list) (LaTeX-enumitem-SetEnumitemKey-list)) ;; New values defined available keys: We have to collect predefined ;; values (if any) from `LaTeX-enumitem-key-val-options' (stored in ;; `vals-predefined') and user-defined values (stored in ;; `vals-parsed') which were parsed and added to `result' in the ;; previous run of `dolist' and then combine them as value to a ;; key. (when (LaTeX-enumitem-SetEnumitemValue-list) (let (result) (dolist (keyvals (LaTeX-enumitem-SetEnumitemValue-list) result) (let* ((key (nth 1 keyvals)) (val (nth 2 keyvals)) (vals-predefined (cadr (assoc key LaTeX-enumitem-key-val-options))) (vals-parsed (cadr (assoc key result)))) ;; Remove entry in `result' if there is one for the `key': (when (assoc key result) (setq result (assq-delete-all (car (assoc key result)) result))) ;; Add the entry to `result'; also remove any duplicates (cl-pushnew (list key (TeX-delete-duplicate-strings (append vals-parsed vals-predefined (list val)))) result :test #'equal))))) ;; New values to `align' key: We collect the predefined ones from ;; `LaTeX-enumitem-key-val-options' in `vals-predefined' and ;; prepend them to newly parsed ones: (when (LaTeX-enumitem-SetLabelAlign-list) (let* ((key "PI:KEY:<KEY>END_PI") (vals (mapcar #'car (LaTeX-enumitem-SetLabelAlign-list))) (vals-predefined (cadr (assoc key LaTeX-enumitem-key-val-options)))) `(("align" ,(TeX-delete-duplicate-strings (append vals-predefined vals)))))) ;; Predefined key=vals: LaTeX-enumitem-key-val-options)) ;; Setup for \newlist: (TeX-auto-add-type "enumitem-newlist" "LaTeX") (defvar LaTeX-enumitem-newlist-regexp '("\\\\newlist{\\([^}]+\\)}{\\([^}]+\\)}" (1 2) LaTeX-auto-enumitem-newlist) "Matches the arguments of `\\newlist' from `enumitem' package.") ;; Setup for \SetLabelAlign: (TeX-auto-add-type "enumitem-SetLabelAlign" "LaTeX") (defvar LaTeX-enumitem-SetLabelAlign-regexp '("\\\\SetLabelAlign{\\([^}]+\\)}" 1 LaTeX-auto-enumitem-SetLabelAlign) "Matches the argument of `\\SetLabelAlign' from `enumitem' package.") ;; Setup for \SetEnumitemKey: (TeX-auto-add-type "enumitem-SetEnumitemKey" "LaTeX") (defvar LaTeX-enumitem-SetEnumitemKey-regexp '("\\\\SetEnumitemKey{\\([^}]+\\)}" 1 LaTeX-auto-enumitem-SetEnumitemKey) "Matches the arguments of `\\SetEnumitemKey' from `enumitem' package.") ;; Setup for \SetEnumitemValue: (TeX-auto-add-type "enumitem-SetEnumitemValue" "LaTeX") ;; Upon Tassilo's recommendation, we include also `0' so that we can ;; use the function `LaTeX-enumitem-SetEnumitemValue-list' while we ;; make sure that `TeX-auto-list-information' doesn't remove multiple ;; defined values to a specific key. For this reason, we also ignore ;; the 3. argument to the `\SetEnumitemValue' macro (i.e., a third ;; {\\([^}]+\\)} in regex) so that we don't pollute the generated ;; `docname.el' with unnecessary (La)TeX code. (defvar LaTeX-enumitem-SetEnumitemValue-regexp '("\\\\SetEnumitemValue{\\([^}]+\\)}{\\([^}]+\\)}" (0 1 2) LaTeX-auto-enumitem-SetEnumitemValue) "Matches the arguments of `\\SetEnumitemValue' from `enumitem' package.") ;; Plug them into the machinery. (defun LaTeX-enumitem-auto-prepare () "Clear various `LaTeX-enumitem-*' before parsing." (setq LaTeX-auto-enumitem-newlist nil LaTeX-auto-enumitem-SetLabelAlign nil LaTeX-auto-enumitem-SetEnumitemKey nil LaTeX-auto-enumitem-SetEnumitemValue nil)) (defun LaTeX-enumitem-auto-cleanup () "Move parsing results into right places for further usage." ;; \newlist{<name>}{<type>}{<max-depth>} ;; env=<name>, type=<type>, ignored=<max-depth> (dolist (env-type (LaTeX-enumitem-newlist-list)) (let* ((env (car env-type)) (type (cadr env-type))) (LaTeX-add-environments (list env 'LaTeX-enumitem-env-with-opts)) ;; Tell AUCTeX about parsed description like environments. (when (or (string-equal type "description") (string-equal type "description*")) (add-to-list 'LaTeX-item-list `(,env . LaTeX-item-argument))) ;; Add new env's to `ispell-tex-skip-alist': skip the opt. arg: (TeX-ispell-skip-setcdr `((,env ispell-tex-arg-end 0)))))) (add-hook 'TeX-auto-prepare-hook #'LaTeX-enumitem-auto-prepare t) (add-hook 'TeX-auto-cleanup-hook #'LaTeX-enumitem-auto-cleanup t) (add-hook 'TeX-update-style-hook #'TeX-auto-parse t) (defun LaTeX-enumitem-env-with-opts (env) "Insert ENV provided by `enumitem' package." (LaTeX-insert-environment env (let ((opts (TeX-read-key-val t (LaTeX-enumitem-key-val-options)))) (when (and opts (not (string-equal opts ""))) (format "[%s]" opts)))) (if (TeX-active-mark) (progn (LaTeX-find-matching-begin) (end-of-line 1)) (end-of-line 0)) (delete-char 1) (when (looking-at (concat "^[ \t]+$\\|" "^[ \t]*" TeX-comment-start-regexp "+[ \t]*$")) (delete-region (point) (line-end-position))) (delete-horizontal-space) ;; Deactivate the mark here in order to prevent `TeX-parse-macro' ;; from swapping point and mark and the \item ending up right after ;; \begin{...}. (deactivate-mark) (LaTeX-insert-item) ;; The inserted \item may have outdented the first line to the ;; right. Fill it, if appropriate. (when (and auto-fill-function (not (looking-at "$")) (not (assoc env LaTeX-indent-environment-list)) (> (- (line-end-position) (line-beginning-position)) (current-fill-column))) (LaTeX-fill-paragraph nil))) (defun LaTeX-arg-enumitem-SetLabelAlign (optional) "Ask and insert a new type (value) for the \"align\" key. Insert value in brackets if OPTIONAL is non-nil." (let ((val (TeX-read-string "Alignment: "))) (TeX-argument-insert val optional) (LaTeX-add-enumitem-SetLabelAligns val))) (defun LaTeX-arg-enumitem-SetEnumitemKey (optional) "Ask and insert a new key and its replacement. Insert key and value in brackets if OPTIONAL is non-nil." (let ((key (TeX-read-string "New Key: ")) (replace (TeX-read-key-val optional (LaTeX-enumitem-key-val-options) "Replacement"))) (TeX-argument-insert key optional) (TeX-argument-insert replace optional) (LaTeX-add-enumitem-SetEnumitemKeys key))) ;; In `LaTeX-enumitem-SetEnumitemValue-regexp', we match (0 1 2). ;; When adding a new `key=val', we need something unique for `0'-match ;; until the next `C-c C-n'. We mimic that regex-match bei concat'ing ;; the elements and pass the result to ;; `LaTeX-add-enumitem-SetEnumitemValues'. It will vanish upon next ;; invocation of `C-c C-n'. (defun LaTeX-arg-enumitem-SetEnumitemValue (optional) "Ask and insert for a new value added to an existing key. Insert key and value in brackets if OPTIONAL is non-nil." (let ((key (completing-read "Key: " LaTeX-enumitem-key-val-options)) (val (TeX-read-string "String value: "))) (TeX-argument-insert key optional) (TeX-argument-insert val optional) (LaTeX-add-enumitem-SetEnumitemValues (list (concat "\\SetEnumitemValue{" key "}{" val "}") key val)))) (defun LaTeX-arg-enumitem-setlist (_optional) "Insert the arguments of `\\setlist' macro from `enumitem' package. This function inserts three arguments. The first optional argument is only available when the package option `sizes' is provided. OPTIONAL is ignored." ;; First opt. argument: (when (LaTeX-provided-package-options-member "enumitem" "sizes") (let* ((TeX-arg-opening-brace "<") (TeX-arg-closing-brace ">") (sizes '("script" "tiny" "footnote" "small" "normal" "large" "Large" "LARGE" "huge" "Huge")) (size (completing-read (TeX-argument-prompt t nil "Size") (append (mapcar (lambda (x) (concat "-" x)) sizes) (mapcar (lambda (x) (concat x "-")) sizes) sizes)))) (TeX-argument-insert size t))) ;; Second opt. argument: (TeX-argument-insert (mapconcat #'identity (TeX-completing-read-multiple (TeX-argument-prompt t nil "Environment(s), level(s)") (append (when (LaTeX-provided-package-options-member "enumitem" "includedisplayed") '("trivlist")) (mapcar #'car (LaTeX-enumitem-newlist-list)) '("1" "2" "3" "4"))) ",") t) ;; Mandatory argument: (TeX-argument-insert (TeX-read-key-val nil (LaTeX-enumitem-key-val-options)) nil)) (TeX-add-style-hook "enumitem" (lambda () ;; Add enumitem to the parser. (TeX-auto-add-regexp LaTeX-enumitem-newlist-regexp) (TeX-auto-add-regexp LaTeX-enumitem-SetEnumitemKey-regexp) (TeX-auto-add-regexp LaTeX-enumitem-SetEnumitemValue-regexp) (TeX-auto-add-regexp LaTeX-enumitem-SetLabelAlign-regexp) ;; Add the standard environments: (LaTeX-add-enumitem-newlists '("itemize" "itemize") '("enumerate" "enumerate") '("description" "description")) ;; Add the starred versions with the 'inline' package option: (when (LaTeX-provided-package-options-member "enumitem" "inline") (LaTeX-add-enumitem-newlists '("itemize*" "itemize*") '("enumerate*" "enumerate*") '("description*" "description*"))) ;; Standard env's take key-val as optional argument. (LaTeX-add-environments '("itemize" LaTeX-enumitem-env-with-opts) '("enumerate" LaTeX-enumitem-env-with-opts) '("description" LaTeX-enumitem-env-with-opts)) ;; Make inline env's available with package option "inline" (when (LaTeX-provided-package-options-member "enumitem" "inline") (LaTeX-add-environments '("itemize*" LaTeX-enumitem-env-with-opts) '("enumerate*" LaTeX-enumitem-env-with-opts) '("description*" LaTeX-enumitem-env-with-opts)) (add-to-list 'LaTeX-item-list '("description*" . LaTeX-item-argument))) (TeX-add-symbols ;; 6 Size dependent settings '("SetEnumitemSize" 2) ;; 7 Cloning the basic lists ;; The easy way would be: ;; '("newlist" ;; "Name" (TeX-arg-eval ;; completing-read "Type: " ;; '(("itemize") ("enumerate") ("description") ;; ("itemize*") ("enumerate*") ("description*"))) ;; "Max-depth") ;; But we go the extra mile to improve the user experience and add ;; the arguments directly to appropriate lists. ;; \newlist{<name>}{<type>}{<max-depth>} '("newlist" (TeX-arg-eval (lambda () (let ((name (TeX-read-string "Name: ")) (type (completing-read "Type: " (mapcar #'cadr (LaTeX-enumitem-newlist-list)))) (depth (TeX-read-string "Max-depth: "))) (when (or (string-equal type "description") (string-equal type "description*")) (add-to-list 'LaTeX-item-list `(,name . LaTeX-item-argument))) (LaTeX-add-environments `(,name LaTeX-enumitem-env-with-opts)) (LaTeX-add-enumitem-newlists (list name type)) (TeX-ispell-skip-setcdr `((,name ispell-tex-arg-end 0))) (TeX-argument-insert name nil) (TeX-argument-insert type nil) (format "%s" depth))))) ;; \renewlist{<name>}{<type>}{<max-depth>} '("renewlist" (TeX-arg-eval completing-read "Name: " (mapcar #'car (LaTeX-enumitem-newlist-list))) (TeX-arg-eval completing-read "Type: " (mapcar #'cadr (LaTeX-enumitem-newlist-list))) "Max-depth") ;; \setlist<size>[<names,levels>]{<key-vals>} '("setlist" LaTeX-arg-enumitem-setlist) ;; \setlist*[<names,levels>]{<key-vals>} '("setlist*" [TeX-arg-eval mapconcat #'identity (TeX-completing-read-multiple (TeX-argument-prompt t nil "Environment(s), level(s)") (append (when (LaTeX-provided-package-options-member "enumitem" "includedisplayed") '("trivlist")) (mapcar #'car (LaTeX-enumitem-newlist-list)) '("1" "2" "3" "4"))) ","] (TeX-arg-key-val (LaTeX-enumitem-key-val-options))) ) ;; General commands: (TeX-add-symbols ;; Ask for an Integer and insert it. '("setlistdepth" "Integer") ;; Just add the braces and let the user do the rest. '("AddEnumerateCounter" 3) '("AddEnumerateCounter*" 3) ;; "\restartlist" only works for lists defined with "resume" key. ;; We will not extract that information and leave that to users. ;; For completion, extract enumerated environments from ;; `LaTeX-enumitem-newlist-list' and add "enumerate" to them. '("restartlist" (TeX-arg-eval (lambda () (let ((enums '("enumerate"))) (when (LaTeX-provided-package-options-member "enumitem" "inline") (cl-pushnew "enumerate*" enums :test #'equal)) (dolist (env-type (LaTeX-enumitem-newlist-list)) (let ((env (car env-type)) (type (cadr env-type))) (when (or (string-equal type "enumerate") (string-equal type "enumerate*")) (cl-pushnew env enums :test #'equal)))) (completing-read "List name: " enums))))) ;; "Align" is added as new value to "align" key in key-val list. '("SetLabelAlign" LaTeX-arg-enumitem-SetLabelAlign t) ;; "Key" will be parsed and added to key-val list. '("SetEnumitemKey" LaTeX-arg-enumitem-SetEnumitemKey) ;; "Key" and "Value" are added to our key-val list. '("SetEnumitemValue" LaTeX-arg-enumitem-SetEnumitemValue "Replacement") ;; v3.6 has a macro for visual debugging. '("DrawEnumitemLabel" 0)) ;; Setting enumerate short label (when (LaTeX-provided-package-options-member "enumitem" "shortlabels") (TeX-add-symbols '("SetEnumerateShortLabel" (TeX-arg-eval completing-read "Key: " '("A" "a" "I" "i" "1")) "Replacement"))) ;; Add \labelindent to list of known lengths: (LaTeX-add-lengths "labelindent") ;; Fontification (when (and (featurep 'font-latex) (eq TeX-install-font-lock 'font-latex-setup)) (font-latex-add-keywords '(("newlist" "{{{") ("renewlist" "{{{") ("SetEnumitemSize" "{{") ("AddEnumerateCounter" "*{{{") ("SetLabelAlign" "{{") ("SetEnumitemKey" "{{" ) ("SetEnumitemValue" "{{{")) 'function) ;; Cater for additional optionals arg <size> based on package ;; option 'sizes': (font-latex-add-keywords (if (LaTeX-provided-package-options-member "enumitem" "sizes") '(("setlist" "*<[{")) '(("setlist" "*[{"))) 'function) (font-latex-add-keywords '(("restartlist" "{" ) ("setlistdepth" "{" ) ("SetEnumerateShortLabel" "{{")) 'variable))) TeX-dialect) (defvar LaTeX-enumitem-package-options '("inline" "shortlabels" "loadonly" "sizes" "ignoredisplayed" "includedisplayed") "Package options for the enumitem package.") ;;; enumitem.el ends here
[ { "context": "exical-binding: t; -*-\n\n;; Copyright (C) 2015-2016 Ivan Malison\n\n;; This program is free software; you can redist", "end": 122, "score": 0.9998424649238586, "start": 110, "tag": "NAME", "value": "Ivan Malison" } ]
.emacs.d/plugins/multi-line/multi-line-decorator.el
articuluxe/harmsway
2
;;; multi-line-decorator.el --- multi-line statements -*- lexical-binding: t; -*- ;; Copyright (C) 2015-2016 Ivan Malison ;; 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: ;; multi-line-decorator defines a collection of decorator respacers ;; that can be used to add behavior to existing respacers. ;;; Code: (require 'eieio) (require 'shut-up) (require 'multi-line-candidate) (require 'multi-line-respace) (require 'multi-line-shared) (put 'multi-line-pre-decorator 'lisp-indent-function 'defun) (put 'multi-line-post-decorator 'lisp-indent-function 'defun) (put 'multi-line-post-all-decorator 'lisp-indent-function 'defun) (defmacro multi-line-compose (name &rest funcs) "Build a new function with NAME that is the composition of FUNCS." `(defun ,name (arg) (multi-line-compose-helper ,funcs))) (defmacro multi-line-compose-helper (funcs) "Builds funcalls of FUNCS applied to the arg." (if (equal (length funcs) 0) (quote arg) `(funcall ,(car funcs) (multi-line-compose-helper ,(cdr funcs))))) ;; TODO: Get rid of inheritance here (defclass multi-line-each-decorator (multi-line-respacer) ((respacer :initarg :respacer) (decorator :initarg :decorator))) (defmethod multi-line-respace-one ((decorator multi-line-each-decorator) index candidates) (funcall (oref decorator decorator) (oref decorator respacer) index candidates)) (defmacro multi-line-pre-decorator (name &rest forms) "Build respacer decorator NAME that execute FORMS before each respacing. FORMS can use the variables index and candidates which will be appropriately populated by the executor." `(defun ,name (decorated-respacer) (make-instance 'multi-line-each-decorator :respacer decorated-respacer :decorator (lambda (respacer index candidates) ,@forms (multi-line-respace-one respacer index candidates))))) (defmacro multi-line-post-decorator (name &rest forms) "Build respacer decorator NAME that execute FORMS after each respacing. FORMS can use the variables index and candidates which will be appropriately populated by the executor." `(defun ,name (respacer) (make-instance 'multi-line-each-decorator :respacer respacer :decorator (lambda (respacer index candidates) (multi-line-respace-one respacer index candidates) ,@forms)))) (defmacro multi-line-post-all-decorator (name &rest forms) "Build respacer decorator NAME that execute FORMS after all respacing. FORMS can use the variables index and candidates which will be appropriately populated by the executor." `(multi-line-post-decorator ,name (when (equal index (- (length candidates) 1)) (goto-char (multi-line-candidate-position (car (last candidates)))) ,@forms))) (multi-line-pre-decorator multi-line-space-clearing-respacer (multi-line-clear-whitespace-at-point)) (multi-line-post-all-decorator multi-line-trailing-comma-respacer (multi-line-add-remove-or-leave-final-comma)) (multi-line-post-decorator multi-line-reindenting-respacer (shut-up (indent-region (multi-line-candidate-position (car candidates)) (multi-line-candidate-position (car (last candidates)))))) (multi-line-compose multi-line-clearing-reindenting-respacer 'multi-line-reindenting-respacer 'multi-line-space-clearing-respacer) (defclass multi-line-space-restoring-respacer () ((respacer :initarg :respacer))) (defmethod multi-line-respace-one ((respacer multi-line-space-restoring-respacer) index candidates) (cl-destructuring-bind (startm . endm) (multi-line-space-markers) (let* ((start (marker-position startm)) (end (marker-position endm)) (spanning-start (progn (goto-char (- start 1)) (point-marker))) (spanning-end (progn (goto-char (+ end 1)) (point-marker))) (space-to-restore (buffer-substring start end))) (delete-region start end) (let ((spanning-string (buffer-substring (marker-position spanning-start) (marker-position spanning-end)))) (multi-line-respace-one (oref respacer respacer) index candidates) (when (equal (buffer-substring (marker-position spanning-start) (marker-position spanning-end)) spanning-string) (goto-char (marker-position startm)) (insert space-to-restore)))))) (defun multi-line-restoring-reindenting-respacer (respacer) (multi-line-reindenting-respacer (multi-line-space-restoring-respacer :respacer respacer))) (provide 'multi-line-decorator) ;;; multi-line-decorator.el ends here
36373
;;; multi-line-decorator.el --- multi-line statements -*- lexical-binding: t; -*- ;; Copyright (C) 2015-2016 <NAME> ;; 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: ;; multi-line-decorator defines a collection of decorator respacers ;; that can be used to add behavior to existing respacers. ;;; Code: (require 'eieio) (require 'shut-up) (require 'multi-line-candidate) (require 'multi-line-respace) (require 'multi-line-shared) (put 'multi-line-pre-decorator 'lisp-indent-function 'defun) (put 'multi-line-post-decorator 'lisp-indent-function 'defun) (put 'multi-line-post-all-decorator 'lisp-indent-function 'defun) (defmacro multi-line-compose (name &rest funcs) "Build a new function with NAME that is the composition of FUNCS." `(defun ,name (arg) (multi-line-compose-helper ,funcs))) (defmacro multi-line-compose-helper (funcs) "Builds funcalls of FUNCS applied to the arg." (if (equal (length funcs) 0) (quote arg) `(funcall ,(car funcs) (multi-line-compose-helper ,(cdr funcs))))) ;; TODO: Get rid of inheritance here (defclass multi-line-each-decorator (multi-line-respacer) ((respacer :initarg :respacer) (decorator :initarg :decorator))) (defmethod multi-line-respace-one ((decorator multi-line-each-decorator) index candidates) (funcall (oref decorator decorator) (oref decorator respacer) index candidates)) (defmacro multi-line-pre-decorator (name &rest forms) "Build respacer decorator NAME that execute FORMS before each respacing. FORMS can use the variables index and candidates which will be appropriately populated by the executor." `(defun ,name (decorated-respacer) (make-instance 'multi-line-each-decorator :respacer decorated-respacer :decorator (lambda (respacer index candidates) ,@forms (multi-line-respace-one respacer index candidates))))) (defmacro multi-line-post-decorator (name &rest forms) "Build respacer decorator NAME that execute FORMS after each respacing. FORMS can use the variables index and candidates which will be appropriately populated by the executor." `(defun ,name (respacer) (make-instance 'multi-line-each-decorator :respacer respacer :decorator (lambda (respacer index candidates) (multi-line-respace-one respacer index candidates) ,@forms)))) (defmacro multi-line-post-all-decorator (name &rest forms) "Build respacer decorator NAME that execute FORMS after all respacing. FORMS can use the variables index and candidates which will be appropriately populated by the executor." `(multi-line-post-decorator ,name (when (equal index (- (length candidates) 1)) (goto-char (multi-line-candidate-position (car (last candidates)))) ,@forms))) (multi-line-pre-decorator multi-line-space-clearing-respacer (multi-line-clear-whitespace-at-point)) (multi-line-post-all-decorator multi-line-trailing-comma-respacer (multi-line-add-remove-or-leave-final-comma)) (multi-line-post-decorator multi-line-reindenting-respacer (shut-up (indent-region (multi-line-candidate-position (car candidates)) (multi-line-candidate-position (car (last candidates)))))) (multi-line-compose multi-line-clearing-reindenting-respacer 'multi-line-reindenting-respacer 'multi-line-space-clearing-respacer) (defclass multi-line-space-restoring-respacer () ((respacer :initarg :respacer))) (defmethod multi-line-respace-one ((respacer multi-line-space-restoring-respacer) index candidates) (cl-destructuring-bind (startm . endm) (multi-line-space-markers) (let* ((start (marker-position startm)) (end (marker-position endm)) (spanning-start (progn (goto-char (- start 1)) (point-marker))) (spanning-end (progn (goto-char (+ end 1)) (point-marker))) (space-to-restore (buffer-substring start end))) (delete-region start end) (let ((spanning-string (buffer-substring (marker-position spanning-start) (marker-position spanning-end)))) (multi-line-respace-one (oref respacer respacer) index candidates) (when (equal (buffer-substring (marker-position spanning-start) (marker-position spanning-end)) spanning-string) (goto-char (marker-position startm)) (insert space-to-restore)))))) (defun multi-line-restoring-reindenting-respacer (respacer) (multi-line-reindenting-respacer (multi-line-space-restoring-respacer :respacer respacer))) (provide 'multi-line-decorator) ;;; multi-line-decorator.el ends here
true
;;; multi-line-decorator.el --- multi-line statements -*- lexical-binding: t; -*- ;; Copyright (C) 2015-2016 PI:NAME:<NAME>END_PI ;; 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: ;; multi-line-decorator defines a collection of decorator respacers ;; that can be used to add behavior to existing respacers. ;;; Code: (require 'eieio) (require 'shut-up) (require 'multi-line-candidate) (require 'multi-line-respace) (require 'multi-line-shared) (put 'multi-line-pre-decorator 'lisp-indent-function 'defun) (put 'multi-line-post-decorator 'lisp-indent-function 'defun) (put 'multi-line-post-all-decorator 'lisp-indent-function 'defun) (defmacro multi-line-compose (name &rest funcs) "Build a new function with NAME that is the composition of FUNCS." `(defun ,name (arg) (multi-line-compose-helper ,funcs))) (defmacro multi-line-compose-helper (funcs) "Builds funcalls of FUNCS applied to the arg." (if (equal (length funcs) 0) (quote arg) `(funcall ,(car funcs) (multi-line-compose-helper ,(cdr funcs))))) ;; TODO: Get rid of inheritance here (defclass multi-line-each-decorator (multi-line-respacer) ((respacer :initarg :respacer) (decorator :initarg :decorator))) (defmethod multi-line-respace-one ((decorator multi-line-each-decorator) index candidates) (funcall (oref decorator decorator) (oref decorator respacer) index candidates)) (defmacro multi-line-pre-decorator (name &rest forms) "Build respacer decorator NAME that execute FORMS before each respacing. FORMS can use the variables index and candidates which will be appropriately populated by the executor." `(defun ,name (decorated-respacer) (make-instance 'multi-line-each-decorator :respacer decorated-respacer :decorator (lambda (respacer index candidates) ,@forms (multi-line-respace-one respacer index candidates))))) (defmacro multi-line-post-decorator (name &rest forms) "Build respacer decorator NAME that execute FORMS after each respacing. FORMS can use the variables index and candidates which will be appropriately populated by the executor." `(defun ,name (respacer) (make-instance 'multi-line-each-decorator :respacer respacer :decorator (lambda (respacer index candidates) (multi-line-respace-one respacer index candidates) ,@forms)))) (defmacro multi-line-post-all-decorator (name &rest forms) "Build respacer decorator NAME that execute FORMS after all respacing. FORMS can use the variables index and candidates which will be appropriately populated by the executor." `(multi-line-post-decorator ,name (when (equal index (- (length candidates) 1)) (goto-char (multi-line-candidate-position (car (last candidates)))) ,@forms))) (multi-line-pre-decorator multi-line-space-clearing-respacer (multi-line-clear-whitespace-at-point)) (multi-line-post-all-decorator multi-line-trailing-comma-respacer (multi-line-add-remove-or-leave-final-comma)) (multi-line-post-decorator multi-line-reindenting-respacer (shut-up (indent-region (multi-line-candidate-position (car candidates)) (multi-line-candidate-position (car (last candidates)))))) (multi-line-compose multi-line-clearing-reindenting-respacer 'multi-line-reindenting-respacer 'multi-line-space-clearing-respacer) (defclass multi-line-space-restoring-respacer () ((respacer :initarg :respacer))) (defmethod multi-line-respace-one ((respacer multi-line-space-restoring-respacer) index candidates) (cl-destructuring-bind (startm . endm) (multi-line-space-markers) (let* ((start (marker-position startm)) (end (marker-position endm)) (spanning-start (progn (goto-char (- start 1)) (point-marker))) (spanning-end (progn (goto-char (+ end 1)) (point-marker))) (space-to-restore (buffer-substring start end))) (delete-region start end) (let ((spanning-string (buffer-substring (marker-position spanning-start) (marker-position spanning-end)))) (multi-line-respace-one (oref respacer respacer) index candidates) (when (equal (buffer-substring (marker-position spanning-start) (marker-position spanning-end)) spanning-string) (goto-char (marker-position startm)) (insert space-to-restore)))))) (defun multi-line-restoring-reindenting-respacer (respacer) (multi-line-reindenting-respacer (multi-line-space-restoring-respacer :respacer respacer))) (provide 'multi-line-decorator) ;;; multi-line-decorator.el ends here
[{"context":" -*- lexical-binding: t -*-\n\n;; Copyright (C) 2016 Radon Rosborough\n\n;; Author: Rad(...TRUNCATED)
el-patch.el
jellelicht/el-patch
0
";;; el-patch.el --- Future-proof your Elisp -*- lexical-binding: t -*-\n\n;; Copyright (C) 2016 Rad(...TRUNCATED)
27120
";;; el-patch.el --- Future-proof your Elisp -*- lexical-binding: t -*-\n\n;; Copyright (C) 2016 <NA(...TRUNCATED)
true
";;; el-patch.el --- Future-proof your Elisp -*- lexical-binding: t -*-\n\n;; Copyright (C) 2016 PI:(...TRUNCATED)
[{"context":"7, 1998 Free Software Foundation, Inc.\n\n;; Author: Bill Rozas <[email protected](...TRUNCATED)
make_1.4/make/inputs/sdir-cov11/lisp/progmodes/scheme.el
m-zakeri/benchmark
0
";;; scheme.el --- Scheme (and DSSSL) editing mode.\n\n;; Copyright (C) 1986, 87, 88, 97, 1998 Free (...TRUNCATED)
42948
";;; scheme.el --- Scheme (and DSSSL) editing mode.\n\n;; Copyright (C) 1986, 87, 88, 97, 1998 Free (...TRUNCATED)
true
";;; scheme.el --- Scheme (and DSSSL) editing mode.\n\n;; Copyright (C) 1986, 87, 88, 97, 1998 Free (...TRUNCATED)
[{"context":"*- lexical-binding: t; -*-\n\n;; Copyright (C) 2022 Troy Brumley\n\n;; Author: Troy Br(...TRUNCATED)
emacs/.emacs.d/site-lisp/init-bgt.el
BlameTroi/.dotfiles
0
";;; init-bgt.el --- blood glucose tracking in org -*- lexical-binding: t; -*-\n\n;; Copyright (C(...TRUNCATED)
32055
";;; init-bgt.el --- blood glucose tracking in org -*- lexical-binding: t; -*-\n\n;; Copyright (C(...TRUNCATED)
true
";;; init-bgt.el --- blood glucose tracking in org -*- lexical-binding: t; -*-\n\n;; Copyright (C(...TRUNCATED)
End of preview. Expand in Data Studio

Dataset Card for "emacs-lisp_checks"

More Information needed

Downloads last month
5