From b7b77a527e4920389667b1ac90c447f52db70996 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Thu, 2 Mar 2023 22:22:16 +0100 Subject: Upgrade .emacs.d/lisp/lua-mode.el and .emacs.d/lisp/markdown-mode.el. Modify .emacs.d/snippets/python-mode/printf --- .emacs.d/lisp/lua-mode.el | 63 +++++++++++++++++++++++++-- .emacs.d/lisp/markdown-mode.el | 49 +++++++++++++++------ .emacs.d/snippets/python-mode.statnett/format | 6 --- .emacs.d/snippets/python-mode.statnett/printf | 2 +- .emacs.d/snippets/python-mode/format | 6 --- .emacs.d/snippets/python-mode/printf | 2 +- 6 files changed, 98 insertions(+), 30 deletions(-) delete mode 100644 .emacs.d/snippets/python-mode.statnett/format delete mode 100644 .emacs.d/snippets/python-mode/format (limited to '.emacs.d') diff --git a/.emacs.d/lisp/lua-mode.el b/.emacs.d/lisp/lua-mode.el index 2d6a2d5..4c543f5 100644 --- a/.emacs.d/lisp/lua-mode.el +++ b/.emacs.d/lisp/lua-mode.el @@ -12,7 +12,7 @@ ;; Aaron Smith . ;; ;; URL: https://immerrr.github.io/lua-mode -;; Version: 20210802 +;; Version: 20221027 ;; Package-Requires: ((emacs "24.3")) ;; ;; This file is NOT part of Emacs. @@ -41,7 +41,8 @@ ;; lua-mode provides support for editing Lua, including automatic ;; indentation, syntactical font-locking, running interactive shell, -;; interacting with `hs-minor-mode' and online documentation lookup. +;; Flymake checks with luacheck, interacting with `hs-minor-mode' and +;; online documentation lookup. ;; The following variables are available for customization (see more via ;; `M-x customize-group lua`): @@ -85,6 +86,10 @@ ;; - Cmd `lua-send-region': send active region ;; - Cmd `lua-restart-with-whole-file': restart REPL and send whole buffer +;; To enable on-the-fly linting, make sure you have the luacheck +;; program installed (available from luarocks) and activate +;; `flymake-mode'. + ;; See "M-x apropos-command ^lua-" for a list of commands. ;; See "M-x customize-group lua" for a list of customizable variables. @@ -710,7 +715,7 @@ index of respective Lua reference manuals.") ;; via `lua-mode-map'. (setq-local electric-indent-chars (append electric-indent-chars lua--electric-indent-chars))) - + (add-hook 'flymake-diagnostic-functions #'lua-flymake nil t) ;; setup menu bar entry (XEmacs style) (if (and (featurep 'menubar) @@ -2194,6 +2199,58 @@ left out." (forward-sexp 1)) (setq count (1- count)))))) +;; Flymake integration + +(defcustom lua-luacheck-program "luacheck" + "Name of the luacheck executable." + :type 'string + :group 'lua) + +(defvar-local lua--flymake-process nil) + +(defun lua-flymake (report-fn &rest _args) + "Flymake backend using the luacheck program. +Takes a Flymake callback REPORT-FN as argument, as expected of a +member of `flymake-diagnostic-functions'." + (when (process-live-p lua--flymake-process) + (kill-process lua--flymake-process)) + (let ((source (current-buffer))) + (save-restriction + (widen) + (setq lua--flymake-process + (make-process + :name "luacheck" :noquery t :connection-type 'pipe + :buffer (generate-new-buffer " *flymake-luacheck*") + :command `(,lua-luacheck-program + "--codes" "--ranges" "--formatter" "plain" "-") + :sentinel + (lambda (proc _event) + (when (eq 'exit (process-status proc)) + (unwind-protect + (if (with-current-buffer source + (eq proc lua--flymake-process)) + (with-current-buffer (process-buffer proc) + (goto-char (point-min)) + (cl-loop + while (search-forward-regexp + "^\\([^:]*\\):\\([0-9]+\\):\\([0-9]+\\)-\\([0-9]+\\): \\(.*\\)$" + nil t) + for line = (string-to-number (match-string 2)) + for col1 = (string-to-number (match-string 3)) + for col2 = (1+ (string-to-number (match-string 4))) + for msg = (match-string 5) + for type = (if (string-match-p "\\`(E" msg) :error :warning) + collect (flymake-make-diagnostic source + (cons line col1) + (cons line col2) + type + msg) + into diags + finally (funcall report-fn diags))) + (flymake-log :warning "Canceling obsolete check %s" proc)) + (kill-buffer (process-buffer proc))))))) + (process-send-region lua--flymake-process (point-min) (point-max)) + (process-send-eof lua--flymake-process)))) ;; menu bar diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index 4e59afa..63a86ad 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el @@ -275,7 +275,7 @@ cause lag when typing on slower machines." (defcustom markdown-uri-types '("acap" "cid" "data" "dav" "fax" "file" "ftp" - "gopher" "http" "https" "imap" "ldap" "mailto" + "geo" "gopher" "http" "https" "imap" "ldap" "mailto" "mid" "message" "modem" "news" "nfs" "nntp" "pop" "prospero" "rtsp" "service" "sip" "tel" "telnet" "tip" "urn" "vemmi" "wais") @@ -880,8 +880,9 @@ Group 6 matches the closing square brackets.") (concat "\\(" (regexp-opt markdown-uri-types) ":[^]\t\n\r<>; ]+\\)") "Regular expression for matching inline URIs.") +;; CommanMark specification says scheme length is 2-32 characters (defconst markdown-regex-angle-uri - (concat "\\(<\\)\\(" (regexp-opt markdown-uri-types) ":[^]\t\n\r<>,;()]+\\)\\(>\\)") + (concat "\\(<\\)\\([a-z][a-z0-9.+-]\\{1,31\\}:[^]\t\n\r<>,;()]+\\)\\(>\\)") "Regular expression for matching inline URIs in angle brackets.") (defconst markdown-regex-email @@ -6408,7 +6409,7 @@ following section." (while (and (not found) (not (bobp)) (re-search-backward markdown-regex-header nil 'move)) - (when (not (markdown-code-block-at-pos (match-beginning 0)))) + (markdown-code-block-at-pos (match-beginning 0)) (setq found (match-beginning 0))) (setq arg (1- arg))) ;; Move forward with negative argument. @@ -6417,7 +6418,7 @@ following section." (while (and (not found) (not (eobp)) (re-search-forward markdown-regex-header nil 'move)) - (when (not (markdown-code-block-at-pos (match-beginning 0)))) + (markdown-code-block-at-pos (match-beginning 0)) (setq found (match-beginning 0))) (setq arg (1+ arg))) (when found @@ -7541,8 +7542,17 @@ This is the inverse of `markdown-live-preview-buffer'.") (defun markdown-live-preview-window-eww (file) "Preview FILE with eww. To be used with `markdown-live-preview-window-function'." + (when (and (bound-and-true-p eww-auto-rename-buffer) + markdown-live-preview-buffer) + (kill-buffer markdown-live-preview-buffer)) (eww-open-file file) - (get-buffer "*eww*")) + ;; #737 if `eww-auto-rename-buffer' is non-nil, the buffer name is not "*eww*" + ;; Try to find the buffer whose name ends with "eww*" + (if (bound-and-true-p eww-auto-rename-buffer) + (cl-loop for buf in (buffer-list) + when (string-match-p "eww\\*\\'" (buffer-name buf)) + return buf) + (get-buffer "*eww*"))) (defun markdown-visual-lines-between-points (beg end) (save-excursion @@ -8596,7 +8606,8 @@ This can be toggled with `markdown-toggle-inline-images' or \\[markdown-toggle-inline-images]." (interactive) (mapc #'delete-overlay markdown-inline-image-overlays) - (setq markdown-inline-image-overlays nil)) + (setq markdown-inline-image-overlays nil) + (when (fboundp 'clear-image-cache) (clear-image-cache))) (defcustom markdown-display-remote-images nil "If non-nil, download and display remote images. @@ -8745,10 +8756,16 @@ mode to use is `tuareg-mode'." LANG is a string, and the returned major mode is a symbol." (cl-find-if 'fboundp - (list (cdr (assoc lang markdown-code-lang-modes)) - (cdr (assoc (downcase lang) markdown-code-lang-modes)) - (intern (concat lang "-mode")) - (intern (concat (downcase lang) "-mode"))))) + (nconc (list (cdr (assoc lang markdown-code-lang-modes)) + (cdr (assoc (downcase lang) markdown-code-lang-modes))) + (and (fboundp 'treesit-language-available-p) + (list (and (treesit-language-available-p (intern lang)) + (intern (concat lang "-ts-mode"))) + (and (treesit-language-available-p (intern (downcase lang))) + (intern (concat (downcase lang) "-ts-mode"))))) + (list + (intern (concat lang "-mode")) + (intern (concat (downcase lang) "-mode")))))) (defun markdown-fontify-code-blocks-generic (matcher last) "Add text properties to next code block from point to LAST. @@ -9186,6 +9203,11 @@ This function assumes point is on a table." (push (buffer-substring-no-properties cur (point-max)) ret)) (nreverse ret)))) +(defsubst markdown--is-delimiter-row (line) + (and (string-match-p "\\`[ \t]*|[ \t]*[-:]" line) + (cl-loop for c across line + always (member c '(?| ?- ?: ?\t ? ))))) + (defun markdown-table-align () "Align table at point. This function assumes point is on a table." @@ -9198,9 +9220,10 @@ This function assumes point is on a table." ;; Store table indent (indent (progn (looking-at "[ \t]*") (match-string 0))) ;; Split table in lines and save column format specifier - (lines (mapcar (lambda (l) - (if (string-match-p "\\`[ \t]*|[ \t]*[-:]" l) - (progn (setq fmtspec (or fmtspec l)) nil) l)) + (lines (mapcar (lambda (line) + (if (markdown--is-delimiter-row line) + (progn (setq fmtspec (or fmtspec line)) nil) + line)) (markdown--split-string (buffer-substring begin end) "\n"))) ;; Split lines in cells (cells (mapcar (lambda (l) (markdown--table-line-to-columns l)) diff --git a/.emacs.d/snippets/python-mode.statnett/format b/.emacs.d/snippets/python-mode.statnett/format deleted file mode 100644 index 85c2d6f..0000000 --- a/.emacs.d/snippets/python-mode.statnett/format +++ /dev/null @@ -1,6 +0,0 @@ -# -*- mode: snippet -*- -# name: format -# key: sf -# group: object oriented -# -- -.format($0) \ No newline at end of file diff --git a/.emacs.d/snippets/python-mode.statnett/printf b/.emacs.d/snippets/python-mode.statnett/printf index c69d6da..229bdd9 100644 --- a/.emacs.d/snippets/python-mode.statnett/printf +++ b/.emacs.d/snippets/python-mode.statnett/printf @@ -2,4 +2,4 @@ # name: printf # key: pf # -- -print("$0{}".format()) \ No newline at end of file +print(f"$0") \ No newline at end of file diff --git a/.emacs.d/snippets/python-mode/format b/.emacs.d/snippets/python-mode/format deleted file mode 100644 index 85c2d6f..0000000 --- a/.emacs.d/snippets/python-mode/format +++ /dev/null @@ -1,6 +0,0 @@ -# -*- mode: snippet -*- -# name: format -# key: sf -# group: object oriented -# -- -.format($0) \ No newline at end of file diff --git a/.emacs.d/snippets/python-mode/printf b/.emacs.d/snippets/python-mode/printf index 78c67a8..087b2eb 100644 --- a/.emacs.d/snippets/python-mode/printf +++ b/.emacs.d/snippets/python-mode/printf @@ -2,4 +2,4 @@ # name: printf # key: pf # -- -print('$0{}'.format()) \ No newline at end of file +print(f'$0') \ No newline at end of file -- cgit v1.3