From debbugs-submit-bounces@debbugs.gnu.org Fri Sep 22 15:40:39 2023 Received: (at submit) by debbugs.gnu.org; 22 Sep 2023 19:40:39 +0000 Received: from localhost ([127.0.0.1]:37307 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjm10-0002Ls-ER for submit@debbugs.gnu.org; Fri, 22 Sep 2023 15:40:39 -0400 Received: from lists.gnu.org ([2001:470:142::17]:36488) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjm0v-0002Ld-6o for submit@debbugs.gnu.org; Fri, 22 Sep 2023 15:40:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qjm0e-0000ek-Nq for bug-gnu-emacs@gnu.org; Fri, 22 Sep 2023 15:40:16 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qjm0c-0006v6-5u for bug-gnu-emacs@gnu.org; Fri, 22 Sep 2023 15:40:16 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-31f71b25a99so2602064f8f.2 for ; Fri, 22 Sep 2023 12:40:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695411612; x=1696016412; darn=gnu.org; h=mime-version:message-id:date:subject:to:from:user-agent:from:to:cc :subject:date:message-id:reply-to; bh=cDdHjBIoHxLr58zV/xga0SdnSRmdNmgUGJums0Y1MVo=; b=ffXK2HxawbfD5UmHhKkZUrlvTpV9X+4gGlzBJVXoejTqXKtWrPZK1cCl8hg0EuIN+V EMnS3D9aqyLHL6cEwj3Qk7sNOYqWMqMkZK+U3MpGEYnCVUKgsqySpXgzbsWt4t3znWPi MDvx00DbthlKk2BVp5zSbveS7TFjdOTSoYEspRzq2qZK+UxvX2uYPDho27T0NSwS7rAl Pau5/1JgAaVwg0yd9FIsRrzSSo8xMmC1RMuoJJb55cheolN+hwe3uHD3uPz3iFES7QO8 sKrjcftgbqo3R1yMCPXV1eJZ2f0CNik5HtYp2N9H4OfiDSJQuVVvAXVRYNmQjBETSJB2 cepw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695411612; x=1696016412; h=mime-version:message-id:date:subject:to:from:user-agent :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cDdHjBIoHxLr58zV/xga0SdnSRmdNmgUGJums0Y1MVo=; b=bsKt1G8JL5NdewWYy/MnPQJ4thgQp5RUaqIx50s1wxhNMDSfPfXu8Sl/1GVR0dDigk PdPMEB8rIbq1kDOnIriGCoMOEAKsVyGWx90cOkWdLumIgX6tjRprp+qKsXjELK5dSHZw /XSjUNG0ibXXoR0IfYIYH+eWzCnR204s5tWowlvodyUCf/2vAngxbd4Wex/0HCSI4FFa 44nTzj0TwREyVBJ+nidfwzR4la2K1edQ4fyHsmv/9dp34tuQ2T2erSBkP7QHYKhVmA0j HZ3lQ4R+Hxh6jD5WI7f7yWMZzEtlxujA98rTYFlLVnhI0sHkb7HClAHCeb6dRW/XgQXM TWvg== X-Gm-Message-State: AOJu0YxH5xHqGoznpZhWuxdq6chmgyu3IECPC728OLjp3odSkYhpVQsh HZZwYvcPPyrC3q51iC7OjacjSFfXNlZBKA== X-Google-Smtp-Source: AGHT+IEQzuW/Yz5mIaXpSyMPyinIBRbKlZbQh4Q74BnWCaJOj0ZTGkOj/0yBSrmV0hQFRI6icysAMA== X-Received: by 2002:a5d:4644:0:b0:319:79b4:a8ba with SMTP id j4-20020a5d4644000000b0031979b4a8bamr464246wrs.41.1695411612094; Fri, 22 Sep 2023 12:40:12 -0700 (PDT) Received: from toolbox.smtp.gmail.com (broadband-90-154-71-4.ip.moscow.rt.ru. [90.154.71.4]) by smtp.gmail.com with ESMTPSA id p7-20020a170906140700b009829d2e892csm3185420ejc.15.2023.09.22.12.40.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:40:11 -0700 (PDT) User-agent: mu4e 1.8.11; emacs 30.0.50 From: Andrey Listopadov To: bug-gnu-emacs@gnu.org Subject: 30.0.50; lua-ts-mode semantic indentation problems Date: Fri, 22 Sep 2023 22:17:55 +0300 Message-ID: <87fs36vvxl.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=andreyorst@gmail.com; helo=mail-wr1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) I've been editing Lua using the long-existing lua-mode[1] and it works well enough for me, but it's indentation implementation is very slow. Indenting a file with just 600 lines takes several seconds on my machine. So when I saw that Emacs now features a lua-ts-mode package in its core, I tried to move to it, in hopes that it would be faster. However, a lot of code is now indented differently, not how I used to, and this creates a lot of noise in commits, as I often re-indent the whole buffer before saving the file. Here are some examples. lua-mode: function foo (e) if e == nil then return 1000 else return e end end lua-ts-mode: function foo (e) if e == nil then return 1000 else return e end end My thoughts: `then' is indented as the part of the block of code that is part of the `true' branch itself. In lua-mode, it is indented the same as `if' itself, and everything after `then' is indented if moved to a new line: function foo (e) if e == nil then return 1000 else return e end end In lua-ts-mode it is indented together with the body which isn't idiomatic: function foo (e) if e == nil then return 1000 else return e end end Another thing that bothers me is that I prefer Gassanenko-style packing of `end' keywords so that they vertically align with the scope of the opened block, as it saves so much vertical space and is easier for me to read, but lua-ts-mode moves it to the latest innermost indentation level, as opposed to the outermost depending on the count of ends in the line itself: function lowest_entropy_cell(world) | local lowest,res=math.huge,nil | for y=1,world.height do | | for x=1,world.width do | | | local cell=world:get(x,y) | | | if cell.is_set then | | | | local e=cell_enthropy(cell) | | | | trace(e) | | | | if e <= lowest then | | | | | lowest,res=e,{x,y} | end end end end | return res or {math.random(world.width),math.random(world.height)} end However, lua-ts-mode indents it like so: function lowest_entropy_cell(world) local lowest,res=math.huge,nil for y=1,world.height do for x=1,world.width do local cell=world:get(x,y) if cell.is_set then local e=cell_enthropy(cell) trace(e) if e <= lowest then lowest,res=e,{x,y} end end end end return res or {math.random(world.width),math.random(world.height)} end I noticed the difference in table indentations as well. lua-mode: local Recipe = { Floor={up={Floor=true,Wall=true}, down={Floor=true,Wall=true}, left={Floor=true,Wall=true}, right={Floor=true,Wall=true}}, Wall={up={Floor=true,Wall=true}, down={Floor=true,Wall=true}, left={Floor=true,Wall=true}, right={Floor=true,Wall=true}}, Corridor={up={Corridoor=true}, down={Corridoor=true}, left={Corridoor=true}, right={Corridoor=true}} } lua-ts-mode: local Recipe = { Floor={up={Floor=true,Wall=true}, down={Floor=true,Wall=true}, left={Floor=true,Wall=true}, right={Floor=true,Wall=true}}, Wall={up={Floor=true,Wall=true}, down={Floor=true,Wall=true}, left={Floor=true,Wall=true}, right={Floor=true,Wall=true}}, Corridor={up={Corridoor=true}, down={Corridoor=true}, left={Corridoor=true}, right={Corridoor=true}} } The first one is more logical and obeys scope levels. Should I expect this to be the default new way of indenting or the indentation can be made to match the lua-mode where it is sensible? Thanks! P.S. I know that stacking `end' isn't really idiomatic Lua style, but it works in old-lua mode sensible enough that it is actually surprising, and transforms Lua into code that is easy to parse just by looking on the indentation level, much like Lisps. [1] https://github.com/immerrr/lua-mode In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version 1.17.8) of 2023-09-18 built on toolbox Repository revision: 861f9cb78370e2b78f852e5ccde9b63c94486ca8 Repository branch: master System Description: Fedora Linux 38 (Container Image) Configured using: 'configure --without-compress-install --with-native-compilation=aot --with-pgtk --with-mailutils --with-xwidgets --prefix=/var/home/alist/.local' Configured features: ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG JSON LCMS2 LIBOTF LIBSELINUX LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PGTK PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER XIM XWIDGETS GTK3 ZLIB Important settings: value of $LANG: en_US.UTF-8 locale-coding-system: utf-8-unix Major mode: Lua Minor modes in effect: repeat-mode: t global-git-commit-mode: t magit-auto-revert-mode: t electric-pair-mode: t hl-todo-mode: t savehist-mode: t delete-selection-mode: t pixel-scroll-precision-mode: t global-auto-revert-mode: t corfu-popupinfo-mode: t global-corfu-mode: t corfu-mode: t global-region-bindings-mode: t recentf-mode: t gcmh-mode: t server-mode: t marginalia-mode: t vertico-mode: t override-global-mode: t tooltip-mode: t global-eldoc-mode: t show-paren-mode: t electric-indent-mode: t mouse-wheel-mode: t menu-bar-mode: t file-name-shadow-mode: t context-menu-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t minibuffer-regexp-mode: t column-number-mode: t line-number-mode: t transient-mark-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t abbrev-mode: t hs-minor-mode: t Load-path shadows: /var/home/alist/.config/emacs/elpa/transient-20230915.1911/transient hides /var/home/alist/.local/share/emacs/30.0.50/lisp/transient /var/home/alist/.config/emacs/elpa/modus-themes-20230916.905/theme-loaddefs hides /var/home/alist/.local/share/emacs/30.0.50/lisp/theme-loaddefs Features: (shadow emacsbug dabbrev lua-ts-mode rect lua-mode modus-operandi-theme python geiser-mode geiser-xref geiser-compile geiser-guile tramp trampver tramp-integration tramp-message tramp-compat tramp-loaddefs info-look geiser geiser-debug geiser-repl geiser-image geiser-capf geiser-doc geiser-menu geiser-autodoc geiser-edit etags fileloop geiser-completion geiser-eval geiser-connection tq geiser-syntax geiser-log geiser-popup geiser-impl help-fns radix-tree geiser-custom geiser-base scheme find-dired grep display-line-numbers css-mode treesit smie mu4e-alert advice time ht alert log4e notifications gntp mu4e mu4e-org mu4e-main mu4e-view mu4e-headers mu4e-compose mu4e-draft mu4e-actions smtpmail mu4e-search mu4e-lists mu4e-bookmarks mu4e-mark mu4e-message flow-fill hl-line mu4e-contacts mu4e-update mu4e-folders mu4e-server mu4e-context mu4e-vars mu4e-helpers mu4e-config ido tabify cus-start repeat files-x org-archive puni pulse color consult ox-odt rng-loc rng-uri rng-parse rng-match rng-dt rng-util rng-pttrn nxml-parse nxml-ns nxml-enc xmltok nxml-util ox-icalendar org-agenda ox-ascii ox-latex ox-hugo ox-hugo-deprecated ffap ox-blackfriday ox-md ox-html table ox-publish tomelr ox sgml-mode facemenu xwidget magit-bookmark bookmark goto-addr vc-hg vc-bzr vc-src vc-sccs vc-svn vc-cvs vc-rcs log-view vc bug-reference vc-git vc-dispatcher misearch multi-isearch dired-aux face-remap magit-extras orderless flyspell ispell org-element org-persist org-id org-refile avl-tree generator oc-basic ol-eww eww xdg url-queue mm-url ol-rmail ol-mhe ol-irc ol-info ol-gnus nnselect gnus-art mm-uu mml2015 mm-view mml-smime smime gnutls dig gnus-sum shr pixel-fill kinsoku url-file svg dom gnus-group gnus-undo gnus-start gnus-dbus gnus-cloud nnimap nnmail mail-source utf7 nnoo parse-time gnus-spec gnus-int gnus-range gnus-win gnus nnheader range ol-docview doc-view jka-compr image-mode exif ol-bibtex bibtex iso8601 ol-bbdb ol-w3m ol-doi org-link-doi org-tempo tempo ob-fennel fennel-proto-repl fennel-mode inf-lisp xref magit-submodule magit-blame magit-stash magit-reflog magit-bisect magit-push magit-pull magit-fetch magit-clone magit-remote magit-commit magit-sequence magit-notes magit-worktree magit-tag magit-merge magit-branch magit-reset magit-files magit-refs magit-status magit magit-repos magit-apply magit-wip magit-log which-func imenu magit-diff smerge-mode diff diff-mode git-commit log-edit message sendmail yank-media puny dired dired-loaddefs rfc822 mml mml-sec epa epg rfc6068 epg-config gnus-util mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr mailabbrev mail-utils gmm-utils mailheader pcvs-util add-log magit-core magit-autorevert magit-margin magit-transient magit-process with-editor magit-mode transient magit-git magit-base magit-section cursor-sensor crm project ob-lua ob-shell shell org ob ob-tangle ob-ref ob-lob ob-table ob-exp org-macro org-src ob-comint org-pcomplete pcomplete org-list org-footnote org-faces org-entities ob-emacs-lisp ob-core ob-eval org-cycle org-table org-keys oc org-loaddefs find-func cal-menu calendar cal-loaddefs vertico-directory mule-util time-date noutline outline elec-pair isayt disp-table hideshow hl-todo savehist delsel pixel-scroll cua-base autorevert filenotify corfu-popupinfo cape corfu region-bindings recentf tree-widget gcmh init proxy gsettings s gvariant parsec dash zig-compilation-mode fennel-compilation-mode clojure-compilation-mode derived compile text-property-search server ediff ediff-merg ediff-mult ediff-wind ediff-diff ediff-help ediff-init ediff-util sql-indent sql view thingatpt comint ansi-osc ring zig-mode reformatter ansi-color ol org-fold org-fold-core org-compat org-version org-macs format-spec blog marginalia vertico compat use-package-delight formfeed modus-vivendi-theme modus-themes dbus xml common-lisp-modes novice cus-edit pp cus-load wid-edit font mode-line edmacro kmacro messages use-package-bind-key bind-key defaults functions local-config delight comp comp-cstr warnings icons rx use-package-ensure cl-extra help-mode use-package-core early-init cape-autoloads clj-decompiler-autoloads clj-refactor-autoloads cider-autoloads clojure-mode-autoloads common-lisp-modes-autoloads consult-autoloads corfu-terminal-autoloads corfu-autoloads csv-mode-autoloads delight-autoloads dumb-jump-autoloads eat-autoloads elfeed-autoloads expand-region-autoloads fennel-mode-autoloads gcmh-autoloads geiser-guile-autoloads geiser-autoloads gsettings-autoloads gvariant-autoloads hl-todo-autoloads inflections-autoloads isayt-autoloads jdecomp-autoloads lisp-extra-font-lock-autoloads lsp-java-autoloads lsp-metals-autoloads dap-mode-autoloads lsp-docker-autoloads bui-autoloads lsp-treemacs-autoloads lsp-mode-autoloads f-autoloads lua-mode-autoloads marginalia-autoloads markdown-mode-autoloads message-view-patch-autoloads magit-autoloads pcase magit-section-autoloads git-commit-autoloads modus-themes-autoloads mu4e-alert-autoloads alert-autoloads log4e-autoloads gntp-autoloads multiple-cursors-autoloads orderless-autoloads org-modern-autoloads org-tree-slide-autoloads ox-hugo-autoloads package-lint-flymake-autoloads package-lint-autoloads paredit-autoloads parsec-autoloads parseedn-autoloads parseclj-autoloads phi-search-autoloads poly-org-autoloads polymode-autoloads popon-autoloads popup-autoloads puni-autoloads easy-mmode finder-inf queue-autoloads racket-mode-autoloads region-bindings-autoloads request-autoloads scala-mode-autoloads separedit-autoloads edit-indirect-autoloads sesman-autoloads sly-autoloads spinner-autoloads sql-indent-autoloads tomelr-autoloads transient-autoloads treemacs-autoloads cfrs-autoloads posframe-autoloads ht-autoloads hydra-autoloads lv-autoloads pfuture-autoloads ace-window-autoloads avy-autoloads s-autoloads dash-autoloads vertico-autoloads vundo-autoloads with-editor-autoloads info compat-autoloads yaml-autoloads yaml-mode-autoloads yasnippet-autoloads zig-mode-autoloads reformatter-autoloads package browse-url url url-proxy url-privacy url-expand url-methods url-history url-cookie generate-lisp-file url-domsuf url-util mailcap url-handlers url-parse auth-source cl-seq eieio eieio-core cl-macs password-cache json subr-x map byte-opt gv bytecomp byte-compile url-vars cl-loaddefs cl-lib rmc iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/pgtk-win pgtk-win term/common-win pgtk-dnd touch-screen tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic indonesian philippine cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp files window text-properties overlay sha1 md5 base64 format env code-pages mule custom widget keymap hashtable-print-readable backquote threads xwidget-internal dbusbind inotify dynamic-setting system-font-setting font-render-setting cairo gtk pgtk lcms2 multi-tty move-toolbar make-network-process native-compile emacs) Memory information: ((conses 16 1147781 1425356) (symbols 48 52742 50) (strings 32 272573 78657) (string-bytes 1 9908365) (vectors 16 119200) (vector-slots 8 2827929 951125) (floats 8 888 21739) (intervals 56 40788 17575) (buffers 992 46)) -- Andrey Listopadov From debbugs-submit-bounces@debbugs.gnu.org Fri Sep 22 15:49:44 2023 Received: (at 66159) by debbugs.gnu.org; 22 Sep 2023 19:49:44 +0000 Received: from localhost ([127.0.0.1]:37317 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjm9o-0002ee-D4 for submit@debbugs.gnu.org; Fri, 22 Sep 2023 15:49:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47790) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjm9l-0002eP-IU for 66159@debbugs.gnu.org; Fri, 22 Sep 2023 15:49:42 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qjm9U-0000In-V9; Fri, 22 Sep 2023 15:49:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=+RODHsUYzxQ2VG1Yk1t4c/IUitZV2TtBXZiSSHqhPbo=; b=eAIzOPL1j4SI IZv47vnKwSNUsjTzZy8QQrFHvwEDs9Pl3xgwKOu38bhPOCZQ0pnqt/AsGshFhgpKydk/2PuPBtQHQ 8W3h3Q2goIpTgEFeq2jzuFK+eJrWgJTVz5N6gkEU3NYttpU4cvXD49WpaQwM/P6rW4B0DZewp/mgj X2Nt6xPy74Bvk0aEZDIVh9x5L8PFwADvJhAESx4LJDJkPNqhhIVPG7FZunz1xbeVYWWtgicpXTKKk vAInu2vqvd9/o2jzXckQh+eh0C5cuO61Pz1M3zsj0hDEY+BjbO5dCNr/N3SPKuqsagd0r/3E4Ijkz 3TO/m4BfQ7NaP9tmEDZGFA==; Date: Fri, 22 Sep 2023 22:49:35 +0300 Message-Id: <83ediq56pc.fsf@gnu.org> From: Eli Zaretskii To: Andrey Listopadov , john muhl In-Reply-To: <87fs36vvxl.fsf@gmail.com> (message from Andrey Listopadov on Fri, 22 Sep 2023 22:17:55 +0300) Subject: Re: bug#66159: 30.0.50; lua-ts-mode semantic indentation problems References: <87fs36vvxl.fsf@gmail.com> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 66159 Cc: 66159@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Andrey Listopadov > Date: Fri, 22 Sep 2023 22:17:55 +0300 > > > I've been editing Lua using the long-existing lua-mode[1] and it works > well enough for me, but it's indentation implementation is very slow. > Indenting a file with just 600 lines takes several seconds on my > machine. So when I saw that Emacs now features a lua-ts-mode package in > its core, I tried to move to it, in hopes that it would be faster. > > However, a lot of code is now indented differently, not how I used to, > and this creates a lot of noise in commits, as I often re-indent the > whole buffer before saving the file. Here are some examples. John, could you please look into this? From debbugs-submit-bounces@debbugs.gnu.org Sun Sep 24 11:07:45 2023 Received: (at 66159) by debbugs.gnu.org; 24 Sep 2023 15:07:45 +0000 Received: from localhost ([127.0.0.1]:43415 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qkQi0-00048n-FQ for submit@debbugs.gnu.org; Sun, 24 Sep 2023 11:07:45 -0400 Received: from out-210.mta1.migadu.com ([2001:41d0:203:375::d2]:57170) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qkQhv-00047T-Ts for 66159@debbugs.gnu.org; Sun, 24 Sep 2023 11:07:43 -0400 References: <87fs36vvxl.fsf@gmail.com> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1695568045; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=J6ZjyJGkPMp23nowzxfksU3+TBimmuG6hiM0sXqndBA=; b=g0Seo2+A+VM+0T0sm1v3MyWbOL8z6aP7BSIDWVWfqyytoXEHhtHftzTKoTWSC91R3ddUSG X0EWXWuS3+OMGFLvG7cm5SaiLwciGrawn0mH2ILNdTHwR85eUBnszHZYKmFybKcH3k3MJu nP0auyDXtFbRkab4x1dZolqjiiho7e0= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: john muhl To: Andrey Listopadov Subject: Re: bug#66159: 30.0.50; lua-ts-mode semantic indentation problems Date: Sun, 24 Sep 2023 10:06:50 -0500 In-reply-to: <87fs36vvxl.fsf@gmail.com> Message-ID: <87v8bz3905.fsf@pub.pink> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Flow: FLOW_OUT X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159 Cc: 66159@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain Andrey Listopadov writes: > I've been editing Lua using the long-existing lua-mode[1] and it works > well enough for me, but it's indentation implementation is very slow. > Indenting a file with just 600 lines takes several seconds on my > machine. So when I saw that Emacs now features a lua-ts-mode package > in its core, I tried to move to it, in hopes that it would be faster. Thanks for trying. > However, a lot of code is now indented differently, not how I used to, > and this creates a lot of noise in commits, as I often re-indent the > whole buffer before saving the file. Here are some examples. The "then" and table examples should indent how you like with the attached patch. Arguments and parameters now also work like your table example so you can have: local function fn(a, b, c, another) end fn(1, 2, 3, {a="first", b="second"}) > Another thing that bothers me is that I prefer Gassanenko-style packing > of `end' keywords so that they vertically align with the scope of the > opened block, as it saves so much vertical space and is easier for me to > read, but lua-ts-mode moves it to the latest innermost indentation > level, as opposed to the outermost depending on the count of ends in the > line itself: > > function lowest_entropy_cell(world) > | local lowest,res=math.huge,nil > | for y=1,world.height do > | | for x=1,world.width do > | | | local cell=world:get(x,y) > | | | if cell.is_set then > | | | | local e=cell_enthropy(cell) > | | | | trace(e) > | | | | if e <= lowest then > | | | | | lowest,res=e,{x,y} > | end end end end > | return res or {math.random(world.width),math.random(world.height)} > end I don't see any reason not to support that style but I'm not sure how to do it. A patch would be welcome but I'll try to figure it out sometime. > Should I expect this to be the default new way of indenting or the > indentation can be made to match the lua-mode where it is sensible? Sure. It's a new mode so nothing is really set in stone. Let me know if you have other suggestions. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Improve-indentation-in-lus-ts-mode-Bug-66159.patch >From d24d1d128fd29ead355334612ccca3f5e2e1fbd2 Mon Sep 17 00:00:00 2001 From: john muhl Date: Sat, 23 Sep 2023 10:49:11 -0500 Subject: [PATCH] Improve indentation in lus-ts-mode (Bug#66159) - Align "then" with if/elseif/else/end when it appears at the beginning of a line. - Anchor indent of the first child in arguments, parameters and tables to the parent and the other children to the first. * lisp/progmodes/lua-ts-mode.el (lua-ts--first-child) (lua-ts--simple-indent-rules): Improve indentation. * test/lisp/progmodes/lua-ts-mode-resources/indent.erts: Add tests. --- lisp/progmodes/lua-ts-mode.el | 17 ++- .../lua-ts-mode-resources/indent.erts | 125 ++++++++++++++++++ 2 files changed, 139 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index 030a3585158..3d946dd1de2 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -233,6 +233,10 @@ lua-ts--font-lock-settings '((ERROR) @font-lock-warning-face)) "Tree-sitter font-lock settings for `lua-ts-mode'.") +(defun lua-ts--first-child (node _p _b &rest _) + "Matches if NODE is the first among its siblings." + (= (treesit-node-index node) 1)) + (defvar lua-ts--simple-indent-rules `((lua ((parent-is "chunk") column-0 0) @@ -240,6 +244,7 @@ lua-ts--simple-indent-rules ((parent-is "block") parent-bol 0) ((node-is "}") parent-bol 0) ((node-is ")") parent-bol 0) + ((node-is "then") standalone-parent 0) ((node-is "else_statement") parent-bol 0) ((node-is "elseif_statement") parent-bol 0) ((node-is "end") parent-bol 0) @@ -251,9 +256,15 @@ lua-ts--simple-indent-rules ((parent-is "else_statement") parent-bol lua-ts-indent-offset) ((parent-is "repeat_statement") parent-bol lua-ts-indent-offset) ((parent-is "while_statement") parent-bol lua-ts-indent-offset) - ((parent-is "table_constructor") parent-bol lua-ts-indent-offset) - ((parent-is "arguments") parent-bol lua-ts-indent-offset) - ((parent-is "parameters") parent-bol lua-ts-indent-offset) + ((and (parent-is "table_constructor") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "table_constructor") (nth-sibling 1) 0) + ((and (parent-is "arguments") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "arguments") (nth-sibling 1) 0) + ((and (parent-is "parameters") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "parameters") (nth-sibling 1) 0) ((parent-is "ERROR") no-indent 0)))) (defvar lua-ts--syntax-table diff --git a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts index 040225c8580..999e01e3e37 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts @@ -32,6 +32,22 @@ f({ ;(function() return false )() + +function foo (e) + if e == nil + then return 1000 + else return e + end +end + +function foo (e) + if e == nil + then + return 1000 + else + return e + end +end =-= print( 0, @@ -57,6 +73,22 @@ f({ ;(function() return false )() + +function foo (e) + if e == nil + then return 1000 + else return e + end +end + +function foo (e) + if e == nil + then + return 1000 + else + return e + end +end =-=-= Name: Argument Indent @@ -77,6 +109,13 @@ cost = 2, length = 8, parallelism = 4, }) + +fn(1, +2, + 3) + +fn(1, 2, +3) =-= function h( string, @@ -93,6 +132,13 @@ local p = h( length = 8, parallelism = 4, }) + +fn(1, + 2, + 3) + +fn(1, 2, + 3) =-=-= Name: Continuation Indent @@ -150,3 +196,82 @@ repeat z = z * 2 until z > 12 =-=-= + +Name: Parameter Indent + +=-= +fn(a, +b) end + +fn(a, b, +c) end + +fn( +a, +b +) end +=-= +fn(a, + b) end + +fn(a, b, + c) end + +fn( + a, + b +) end +=-=-= + +Code: + (lambda () + (setq indent-tabs-mode nil) + (setq lua-ts-indent-offset 4) + (lua-ts-mode) + (indent-region (point-min) (point-max))) + +Name: Table Indent + +=-= +local Recipe = { + Floor={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Wall={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Corridor={up={Corridoor=true}, + down={Corridoor=true}, + left={Corridoor=true}, + right={Corridoor=true}} +} + +local Other = { +a = 1, + b = 2, + c = 3, +} +=-= +local Recipe = { + Floor={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Wall={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Corridor={up={Corridoor=true}, + down={Corridoor=true}, + left={Corridoor=true}, + right={Corridoor=true}} +} + +local Other = { + a = 1, + b = 2, + c = 3, +} +=-=-= -- 2.41.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun Sep 24 11:45:43 2023 Received: (at 66159) by debbugs.gnu.org; 24 Sep 2023 15:45:43 +0000 Received: from localhost ([127.0.0.1]:43472 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qkRIl-00059Q-5r for submit@debbugs.gnu.org; Sun, 24 Sep 2023 11:45:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39046) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qkRIj-00059D-Tw for 66159@debbugs.gnu.org; Sun, 24 Sep 2023 11:45:42 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkRIS-0007ix-O6; Sun, 24 Sep 2023 11:45:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=UJuYTD147jxn4R7ocWHWCNvGFQLzbuES0ngkJoXSPT0=; b=OTlumarOOwLb vV8PswKsS5IN7N2T+4b5ItQAKK/X6DSVqgO9oDoa7ujAXswQ6yv4KZrs8l18igk7uviSU8iHNlXSh bp1UWw1RJIxsNO4yX4q2aGfCavdp7M1zMrSfuchdCdw4Ob2xhduKBK4Ds2mdcYs5wJ0fUZb7+if/O cw5fuLOR59H95Bzo/XsuAFWVGTNA8vCXlEa2LXMWNqhwXgyfwWt0nwu52bMaATju3MoB/hS+2O/2N liTk4x/efvXg2k4yGY5Y95BuD8CNI6V+0l7DSXtpSkOCHhWEgaOS72YZ9Uo5ta5z1ydacdSJD0e2v f0umewvVgOKrGCAGuZPmCg==; Date: Sun, 24 Sep 2023 18:44:54 +0300 Message-Id: <83jzsf379l.fsf@gnu.org> From: Eli Zaretskii To: john muhl In-Reply-To: <87v8bz3905.fsf@pub.pink> (bug-gnu-emacs@gnu.org) Subject: Re: bug#66159: 30.0.50; lua-ts-mode semantic indentation problems References: <87fs36vvxl.fsf@gmail.com> <87v8bz3905.fsf@pub.pink> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 66159 Cc: andreyorst@gmail.com, 66159@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Cc: 66159@debbugs.gnu.org > Date: Sun, 24 Sep 2023 10:06:50 -0500 > From: john muhl via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > > Another thing that bothers me is that I prefer Gassanenko-style packing > > of `end' keywords so that they vertically align with the scope of the > > opened block, as it saves so much vertical space and is easier for me to > > read, but lua-ts-mode moves it to the latest innermost indentation > > level, as opposed to the outermost depending on the count of ends in the > > line itself: > > > > function lowest_entropy_cell(world) > > | local lowest,res=math.huge,nil > > | for y=1,world.height do > > | | for x=1,world.width do > > | | | local cell=world:get(x,y) > > | | | if cell.is_set then > > | | | | local e=cell_enthropy(cell) > > | | | | trace(e) > > | | | | if e <= lowest then > > | | | | | lowest,res=e,{x,y} > > | end end end end > > | return res or {math.random(world.width),math.random(world.height)} > > end > > I don't see any reason not to support that style but I'm not sure how to > do it. A patch would be welcome but I'll try to figure it out sometime. Maybe introduce indentation styles into lua-ts-mode, like CC Mode and c-ts-mode have? From debbugs-submit-bounces@debbugs.gnu.org Sun Sep 24 12:48:22 2023 Received: (at 66159) by debbugs.gnu.org; 24 Sep 2023 16:48:22 +0000 Received: from localhost ([127.0.0.1]:43533 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qkSHO-00071e-8O for submit@debbugs.gnu.org; Sun, 24 Sep 2023 12:48:22 -0400 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]:57496) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qkSHJ-00070X-Aq for 66159@debbugs.gnu.org; Sun, 24 Sep 2023 12:48:21 -0400 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-5033918c09eso7722537e87.2 for <66159@debbugs.gnu.org>; Sun, 24 Sep 2023 09:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695574079; x=1696178879; darn=debbugs.gnu.org; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=fpuQg05mg+Pkn3IThlk3ixR1jySv/uco8UII9j3g97w=; b=FoDX/NBd1iNGRHpT/JO+QjVwLjAMJvsAlsboD15lbMw3jULUH9iDbpgT5ygsTRyXFd Hm5z9WJDxyuVl4UtuU05GjDYgQlMBZ6HxiHb97d1AY7xvNXXYEzhDZ6arcIjN/sjH/Yt Zi7bZ0LS58P9mzclmxn0/IvuNKc/+N8hBmcuxlXpgbDOLPk3+217UkhOmDHLcR0gm+6w LWM8MKeFKDvAe+lMDeFGUPnrvI4hDRowY0iADDOX7xuZm79Cwwun8+6mJ3/CzV6p3/4n mvPjERP0SyAAZD15p3WI2QfsNG4mrmOXtawh4+cNq7S30FnEXhV/WU2cMn+iKaqOLjy9 3X7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695574079; x=1696178879; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=fpuQg05mg+Pkn3IThlk3ixR1jySv/uco8UII9j3g97w=; b=i7/pS+3ihVBaBSV8WYXiHk56qxGWMMZESBJn7aRaKYj/mYnA8EgzySE5MbJPxZYEDC f2mOltGKNrH0OKybTWVZW8ue12DyX5v0iQD8zhxMChWKXu+zX6pYsPt35LPIbpjTgdD3 hKh/wP5ZogUgWlYqoIvysC7vGY6NPodAtP39GdoMmTkBO5ZSRLTnZWCKJ/dTSR2qAn8p meldg6NRlldetBG9juW/krfQC9cLLhprl4e+yrUCtAmF498PTHDIgibWxS6Z0vbVEUZa oTcGQxHJoiOp62c4NUDrqWGW3lMKxDEoANfcHCDcPUfQnw2YIb5LxqyEFKERd0MAjaE0 py6A== X-Gm-Message-State: AOJu0Yx0BsC3j3PIlWPVT9YuMZf6yprrasNbBWty1BXdp9KOq4bHd1Uo G7BZRvsIptsnmvxwoL3VuedAZhgmLK8= X-Google-Smtp-Source: AGHT+IE+5Zm1BuvE3M1tHbUv0L/RYzxfMTFLKoWFr6fCR8EzVESpnus0bydh0GvVWkfHG+QCb9+7SA== X-Received: by 2002:a19:5502:0:b0:4fe:5741:9eb9 with SMTP id n2-20020a195502000000b004fe57419eb9mr3317358lfe.49.1695574079032; Sun, 24 Sep 2023 09:47:59 -0700 (PDT) Received: from toolbox.smtp.gmail.com (broadband-90-154-71-4.ip.moscow.rt.ru. [90.154.71.4]) by smtp.gmail.com with ESMTPSA id v26-20020aa7d65a000000b00530e32d6143sm4503481edr.43.2023.09.24.09.47.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 09:47:58 -0700 (PDT) References: <87fs36vvxl.fsf@gmail.com> <87v8bz3905.fsf@pub.pink> User-agent: mu4e 1.8.11; emacs 30.0.50 From: Andrey Listopadov To: john muhl Subject: Re: bug#66159: 30.0.50; lua-ts-mode semantic indentation problems Date: Sun, 24 Sep 2023 19:38:38 +0300 In-reply-to: <87v8bz3905.fsf@pub.pink> Message-ID: <878r8vwm9v.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159 Cc: 66159@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Thanks! The patch seems to work as I would expect for most cases. > I don't see any reason not to support that style but I'm not sure how to > do it. A patch would be welcome but I'll try to figure it out sometime. A far as I understand it, in the `lua-mode' the overall line indentation is computed via subtracting indentation for every `end' in that line, e.g. `end end end' subtracts `lua-indent-level three times from current indent level. > Sure. It's a new mode so nothing is really set in stone. Let me know if > you have other suggestions. I also noticed that `lua-ts-inferior-lua` for some reason starts itself in a new frame instead of just a new window. I haven't seen this behavior with other inferior-*-modes, and the `lua-start-process' function from `lua-mode' doesn't spawn a new frame either. Looking at the code, it seems that it was a deliberate choice, as I see the use of `display-buffer-pop-up-frame' in the `display-buffer' ACTION arg. -- Andrey Listopadov From debbugs-submit-bounces@debbugs.gnu.org Sun Sep 24 19:03:53 2023 Received: (at 66159) by debbugs.gnu.org; 24 Sep 2023 23:03:53 +0000 Received: from localhost ([127.0.0.1]:43752 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qkY8m-0008M5-PK for submit@debbugs.gnu.org; Sun, 24 Sep 2023 19:03:53 -0400 Received: from out-193.mta1.migadu.com ([2001:41d0:203:375::c1]:44961) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qkY8j-0008Lt-BW for 66159@debbugs.gnu.org; Sun, 24 Sep 2023 19:03:50 -0400 References: <87fs36vvxl.fsf@gmail.com> <87v8bz3905.fsf@pub.pink> <878r8vwm9v.fsf@gmail.com> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1695596615; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PIpDekSVk4mViZBuaZLAK3vc0OkhjnDQ+w+qW54X4MU=; b=cGaQvvmRdbHXF9uJ6iof3MBZvJw5VEmID8ByP4XkMayirWN+9aICBGIDG4O5tdSSGlSl63 RBmXyCFYZPyrm7sC1zEDj3Xp1Z8mtyn4fspSh5u+MjR7zDeiYdeFSa6LyIaMxrpC0t7/Ds QybsE2Scc72K9zDJgv0MniFepHdtv+o= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: john muhl To: Andrey Listopadov Subject: Re: bug#66159: 30.0.50; lua-ts-mode semantic indentation problems Date: Sun, 24 Sep 2023 13:20:23 -0500 In-reply-to: <878r8vwm9v.fsf@gmail.com> Message-ID: <87il7z5g3g.fsf@pub.pink> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Flow: FLOW_OUT X-Spam-Score: 1.1 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Eli Zaretskii writes: >> > Another thing that bothers me is that I prefer Gassanenko-style packing >> > of `end' keywords so that they vertically align with the scope of the >> > opened block, as it saves so much vertical [...] Content analysis details: (1.1 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 1.1 DATE_IN_PAST_03_06 Date: is 3 to 6 hours before Received: date 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-Debbugs-Envelope-To: 66159 Cc: 66159@debbugs.gnu.org, Philip Kaludercic , Eli Zaretskii X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.1 (/) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Eli Zaretskii writes: >> > Another thing that bothers me is that I prefer Gassanenko-style packing >> > of `end' keywords so that they vertically align with the scope of the >> > opened block, as it saves so much vertical space and is easier for me = to >> > read, but lua-ts-mode moves it to the latest innermost indentation >> > level, as opposed to the outermost depending on the count of ends in t= he >> > line itself: >>=20 >> I don't see any reason not to support that style but I'm not sure how to >> do it. A patch would be welcome but I'll try to figure it out sometime. > > Maybe introduce indentation styles into lua-ts-mode, like CC Mode and > c-ts-mode have? I=E2=80=99ll have a look at what the c-ts-mode styles do and see what might= be applicable. In this case the changes can be accommodated by default. Andrey Listopadov writes: > Thanks! The patch seems to work as I would expect for most cases. > >> I don't see any reason not to support that style but I'm not sure how to >> do it. A patch would be welcome but I'll try to figure it out sometime. > > A far as I understand it, in the `lua-mode' the overall line indentation > is computed via subtracting indentation for every `end' in that line, > e.g. `end end end' subtracts `lua-indent-level three times from current > indent level. Thanks for the explanation. The attached patch should make end packing work now. >> Sure. It's a new mode so nothing is really set in stone. Let me know if >> you have other suggestions. > > I also noticed that `lua-ts-inferior-lua` for some reason starts itself > in a new frame instead of just a new window. I haven't seen this > behavior with other inferior-*-modes, and the `lua-start-process' > function from `lua-mode' doesn't spawn a new frame either. > > Looking at the code, it seems that it was a deliberate choice, as I see > the use of `display-buffer-pop-up-frame' in the `display-buffer' ACTION > arg. It did use a window originally but I was asked to change it: >> + (pop-to-buffer buffer))) > > I believe that `display-buffer-pop-up-frame' is the preferred alternative > to `pop-to-buffer' these days. Maybe I misunderstood and it was only about not using =E2=80=98pop-to-buffe= r=E2=80=99 and should have been =E2=80=98display-buffer-pop-up-window=E2=80=99. CC=E2= =80=99d Philip for clarification. If you customize where you want it with =E2=80=98display-buffer-alist=E2=80= =99 that should be respected. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Improve-indentation-in-lus-ts-mode-Bug-66159.patch >From c32ce5aef2c8692cb93e6d91a7dc08af4b50c210 Mon Sep 17 00:00:00 2001 From: john muhl Date: Sat, 23 Sep 2023 10:49:11 -0500 Subject: [PATCH] Improve indentation in lus-ts-mode (Bug#66159) - Align "then" with if/elseif/else/end when it appears at the beginning of a line. - Align a single-line of "end"s with the beginning of the outermost block being closed. - Anchor indent of the first child in arguments, parameters and tables to the parent and the other children to the first. * lisp/progmodes/lua-ts-mode.el (lua-ts--first-child) (lua-ts--end-indent-offset) (lua-ts--simple-indent-rules): Improve indentation. * test/lisp/progmodes/lua-ts-mode-resources/indent.erts: Add tests. --- lisp/progmodes/lua-ts-mode.el | 26 ++- .../lua-ts-mode-resources/indent.erts | 179 ++++++++++++++++++ 2 files changed, 201 insertions(+), 4 deletions(-) diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index 030a3585158..fcab8ec610b 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -233,6 +233,17 @@ lua-ts--font-lock-settings '((ERROR) @font-lock-warning-face)) "Tree-sitter font-lock settings for `lua-ts-mode'.") +(defun lua-ts--first-child (node _p _b &rest _) + "Matches if NODE is the first among its siblings." + (= (treesit-node-index node) 1)) + +(defun lua-ts--end-indent-offset (_n _p _b &rest _) + "Calculate indent offset based on `end' count." + (let* ((beg (line-beginning-position)) + (end (line-end-position)) + (count (count-matches "end" beg end))) + (- (* (1- count) lua-ts-indent-offset)))) + (defvar lua-ts--simple-indent-rules `((lua ((parent-is "chunk") column-0 0) @@ -240,9 +251,10 @@ lua-ts--simple-indent-rules ((parent-is "block") parent-bol 0) ((node-is "}") parent-bol 0) ((node-is ")") parent-bol 0) + ((node-is "then") standalone-parent 0) ((node-is "else_statement") parent-bol 0) ((node-is "elseif_statement") parent-bol 0) - ((node-is "end") parent-bol 0) + ((node-is "end") parent-bol lua-ts--end-indent-offset) ((node-is "until") parent-bol 0) ((parent-is "for_statement") parent-bol lua-ts-indent-offset) ((parent-is "function_declaration") parent-bol lua-ts-indent-offset) @@ -251,9 +263,15 @@ lua-ts--simple-indent-rules ((parent-is "else_statement") parent-bol lua-ts-indent-offset) ((parent-is "repeat_statement") parent-bol lua-ts-indent-offset) ((parent-is "while_statement") parent-bol lua-ts-indent-offset) - ((parent-is "table_constructor") parent-bol lua-ts-indent-offset) - ((parent-is "arguments") parent-bol lua-ts-indent-offset) - ((parent-is "parameters") parent-bol lua-ts-indent-offset) + ((and (parent-is "table_constructor") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "table_constructor") (nth-sibling 1) 0) + ((and (parent-is "arguments") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "arguments") (nth-sibling 1) 0) + ((and (parent-is "parameters") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "parameters") (nth-sibling 1) 0) ((parent-is "ERROR") no-indent 0)))) (defvar lua-ts--syntax-table diff --git a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts index 040225c8580..b0cfe11ef6f 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts @@ -32,6 +32,22 @@ f({ ;(function() return false )() + +function foo (e) + if e == nil + then return 1000 + else return e + end +end + +function foo (e) + if e == nil + then + return 1000 + else + return e + end +end =-= print( 0, @@ -57,6 +73,22 @@ f({ ;(function() return false )() + +function foo (e) + if e == nil + then return 1000 + else return e + end +end + +function foo (e) + if e == nil + then + return 1000 + else + return e + end +end =-=-= Name: Argument Indent @@ -77,6 +109,13 @@ cost = 2, length = 8, parallelism = 4, }) + +fn(1, +2, + 3) + +fn(1, 2, +3) =-= function h( string, @@ -93,6 +132,13 @@ local p = h( length = 8, parallelism = 4, }) + +fn(1, + 2, + 3) + +fn(1, 2, + 3) =-=-= Name: Continuation Indent @@ -150,3 +196,136 @@ repeat z = z * 2 until z > 12 =-=-= + +Name: Parameter Indent + +=-= +fn(a, +b) end + +fn(a, b, +c) end + +fn( +a, +b +) end +=-= +fn(a, + b) end + +fn(a, b, + c) end + +fn( + a, + b +) end +=-=-= + +Code: + (lambda () + (setq indent-tabs-mode nil) + (setq lua-ts-indent-offset 4) + (lua-ts-mode) + (indent-region (point-min) (point-max))) + +Name: Table Indent + +=-= +local Recipe = { + Floor={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Wall={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Corridor={up={Corridoor=true}, + down={Corridoor=true}, + left={Corridoor=true}, + right={Corridoor=true}} +} + +local Other = { +a = 1, + b = 2, + c = 3, +} +=-= +local Recipe = { + Floor={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Wall={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Corridor={up={Corridoor=true}, + down={Corridoor=true}, + left={Corridoor=true}, + right={Corridoor=true}} +} + +local Other = { + a = 1, + b = 2, + c = 3, +} +=-=-= + +Name: Single Line End + +=-= +function lowest_entropy_cell(world) + local lowest,res=math.huge,nil + for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end end end end + return res or {math.random(w.w),math.random(w.h)} +end + +for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end + end end end +=-= +function lowest_entropy_cell(world) + local lowest,res=math.huge,nil + for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end end end end + return res or {math.random(w.w),math.random(w.h)} +end + +for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end +end end end +=-=-= -- 2.41.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 26 15:29:33 2023 Received: (at 66159) by debbugs.gnu.org; 26 Sep 2023 19:29:33 +0000 Received: from localhost ([127.0.0.1]:49767 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qlDkT-0000ds-5C for submit@debbugs.gnu.org; Tue, 26 Sep 2023 15:29:33 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:56830) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qlDkR-0000da-K1 for 66159@debbugs.gnu.org; Tue, 26 Sep 2023 15:29:32 -0400 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9ad8d47ef2fso1159951366b.1 for <66159@debbugs.gnu.org>; Tue, 26 Sep 2023 12:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695756552; x=1696361352; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:from:to:cc:subject:date :message-id:reply-to; bh=aJrx3I8J/q+QAG+iF8Rnr3tLFQ84+2qEOf6dmLKP5DM=; b=FwRs64D4TpiICBOPOpVlzVZ8olWaPkJ/xzaC5GiIyxxAJ/KqOJPdW1ajnQuoU2+BIC gfZ+uPLckoju+RKP9xkL7UITc50YpcqwaGnCAzDlCzGDE+s/1E5rDVGzdJ/PjlPsbcW2 KZm5bdBxXjIFwgQ/duABbgKUj+1B7uEcQLXHskai8wHOCy8D24Mwoy5w+2hkyjVIiRAt L3hDnd5vNPPoPYvrFRuymWSv9SYXrKiA/vC9XvcxaTb6I7WUL+b39MBLxKgfih/+pJ5A Cext0Tnqjr99Yzfqu0VlaWHHpzjPgsli4goU/vMzdzl9CALEH3wvEal1cXQZHKc22RQX YMKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695756552; x=1696361352; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=aJrx3I8J/q+QAG+iF8Rnr3tLFQ84+2qEOf6dmLKP5DM=; b=a58/2lvuDxODquinrxZAutCIcr/65crvg+ZqyVPTE95DAEPFkq7m0rTdKxdn2URa+8 dOanmILs3mM9iTxwGpeHmDoNt/7uwkaZVq5OlnUcAOqy+xWQsAdp7Flc6CpaDuWwDMB1 C87B9cVT8ryhtfKSUDIfA57L/d0YOrmzTz7yWj2YzQQXQC+A0jLOxlIC09Gd+2hBpmdp 6mi3sAwMwryukb1JcxK5qWNS2yRdXW6ILrMNgMBE6RPucQOGG/SAJg0LxwWtWIU+Tkwf /gB+xRMHegQwD5oZnfDBgwJk0xrrvR57K/AeO2f8Sdav6BIgHF2hCax+wJ6gu4ORqIdc uNOA== X-Gm-Message-State: AOJu0Ywa1FqW1Vz29T3nWv7u3QU5c7l2atJS+9wG7LbgsmM29hcwjNdo wZM3BWvlGrGa5KxT5ZpXGSY= X-Google-Smtp-Source: AGHT+IHafGMoyW7szzuMW/S2diMu3iGgveiscM+07/JXzQV8F8AFtIVQzmw6aexK+xnic8HQYMXlYw== X-Received: by 2002:a17:907:77c7:b0:9ad:e180:16e3 with SMTP id kz7-20020a17090777c700b009ade18016e3mr8543152ejc.37.1695756552261; Tue, 26 Sep 2023 12:29:12 -0700 (PDT) Received: from toolbox.smtp.gmail.com (broadband-90-154-71-4.ip.moscow.rt.ru. [90.154.71.4]) by smtp.gmail.com with ESMTPSA id mh2-20020a170906eb8200b0099cc3c7ace2sm8228745ejb.140.2023.09.26.12.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 12:29:11 -0700 (PDT) References: <87fs36vvxl.fsf@gmail.com> <87v8bz3905.fsf@pub.pink> <878r8vwm9v.fsf@gmail.com> <87il7z5g3g.fsf@pub.pink> User-agent: mu4e 1.8.11; emacs 30.0.50 From: Andrey Listopadov To: john muhl Subject: Re: bug#66159: 30.0.50; lua-ts-mode semantic indentation problems Date: Tue, 26 Sep 2023 22:21:35 +0300 In-reply-to: <87il7z5g3g.fsf@pub.pink> Message-ID: <87lecs4ttm.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159 Cc: 66159@debbugs.gnu.org, Philip Kaludercic , Eli Zaretskii X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) john muhl writes: > Eli Zaretskii writes: > >>> > Another thing that bothers me is that I prefer Gassanenko-style packi= ng >>> > of `end' keywords so that they vertically align with the scope of the >>> > opened block, as it saves so much vertical space and is easier for me= to >>> > read, but lua-ts-mode moves it to the latest innermost indentation >>> > level, as opposed to the outermost depending on the count of ends in = the >>> > line itself: >>> >>> I don't see any reason not to support that style but I'm not sure how to >>> do it. A patch would be welcome but I'll try to figure it out sometime. >> >> Maybe introduce indentation styles into lua-ts-mode, like CC Mode and >> c-ts-mode have? > > I=E2=80=99ll have a look at what the c-ts-mode styles do and see what mig= ht be > applicable. In this case the changes can be accommodated by default. In my opinion, this isn't distinct enough to introduce a new style. But it's up to you to decide, of course - I'm all for better editing experience for Lua! >> A far as I understand it, in the `lua-mode' the overall line indentation >> is computed via subtracting indentation for every `end' in that line, >> e.g. `end end end' subtracts `lua-indent-level three times from current >> indent level. > > Thanks for the explanation. The attached patch should make end packing > work now. I've tried your latest patch and indeed `end' now pack themselves as in the lua-mode. Thank you very much! >>> Sure. It's a new mode so nothing is really set in stone. Let me know if >>> you have other suggestions. I noticed that the `do' keyword is indented similarly to `then' before the patch when put on the new line: for i=3D1,10 do print(i) end I'm not sure if that's a proper way to indent it or not though, but `do' usually signifies start of the scope, so perhaps it shouldn't be indented in this case. There are also some weirdness in semantic navigation, but it's more likely that I'm just not used to new ts-backed navigation yet. Thanks for your work on lua-ts-mode, it's much more snappy editing experience now! If you're willing to dig into some (pretty crazy) involved examples, I can send here some really convoluted nested anonymous functions that currently are indented in a weird way in both modes. Neither does it exactly right in my opiion, but I also don't know if there is the right way to indent this. I can send these examples later this week once I finish an article I'm working on rightnow. -- Andrey Listopadov From debbugs-submit-bounces@debbugs.gnu.org Wed Sep 27 00:57:12 2023 Received: (at 66159) by debbugs.gnu.org; 27 Sep 2023 04:57:13 +0000 Received: from localhost ([127.0.0.1]:50244 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qlMbo-0001rf-4V for submit@debbugs.gnu.org; Wed, 27 Sep 2023 00:57:12 -0400 Received: from out-195.mta0.migadu.com ([2001:41d0:1004:224b::c3]:14719) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qlMbj-0001rU-UX for 66159@debbugs.gnu.org; Wed, 27 Sep 2023 00:57:10 -0400 References: <87fs36vvxl.fsf@gmail.com> <87v8bz3905.fsf@pub.pink> <878r8vwm9v.fsf@gmail.com> <87il7z5g3g.fsf@pub.pink> <87lecs4ttm.fsf@gmail.com> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1695790613; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=mlX/4EiKUHhGyWKayE2vQb4GkFjuy0bxT2sqUAcUCjY=; b=Ij9oMr+xTqHUUdfy2epJtM4BnXtyEUQsEyPvTEIH35Rk4r0aXTZDfpjBez9d6P2HgsC6ge DTb3Wm4oY8L8UhDhGdNBVfDX/OomlAiCNM3MXej6U7fiR5/mxuVwAvykhhiG6zPO1Sdi6L yF6WV6fM9poAdGzMcho3BiTdQBpGtfc= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: john muhl To: Andrey Listopadov Subject: Re: bug#66159: 30.0.50; lua-ts-mode semantic indentation problems Date: Tue, 26 Sep 2023 20:18:07 -0500 In-reply-to: <87lecs4ttm.fsf@gmail.com> Message-ID: <87fs302oz3.fsf@pub.pink> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Flow: FLOW_OUT X-Spam-Score: 1.1 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Andrey Listopadov writes: > john muhl writes: > >> Eli Zaretskii writes: >> >>>> > Another thing that bothers me is that I prefer Gassanenko-style packing >>>> > of `end' keywords so that they vert [...] Content analysis details: (1.1 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 1.1 DATE_IN_PAST_03_06 Date: is 3 to 6 hours before Received: date 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-Debbugs-Envelope-To: 66159 Cc: 66159@debbugs.gnu.org, Philip Kaludercic , Eli Zaretskii X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.1 (/) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Andrey Listopadov writes: > john muhl writes: > >> Eli Zaretskii writes: >> >>>> > Another thing that bothers me is that I prefer Gassanenko-style pack= ing >>>> > of `end' keywords so that they vertically align with the scope of the >>>> > opened block, as it saves so much vertical space and is easier for m= e to >>>> > read, but lua-ts-mode moves it to the latest innermost indentation >>>> > level, as opposed to the outermost depending on the count of ends in= the >>>> > line itself: >>>> >>>> I don't see any reason not to support that style but I'm not sure how = to >>>> do it. A patch would be welcome but I'll try to figure it out sometime. >>> >>> Maybe introduce indentation styles into lua-ts-mode, like CC Mode and >>> c-ts-mode have? >> >> I=E2=80=99ll have a look at what the c-ts-mode styles do and see what mi= ght be >> applicable. In this case the changes can be accommodated by default. > > In my opinion, this isn't distinct enough to introduce a new style. > But it's up to you to decide, of course - I'm all for better editing > experience for Lua! I agree there=E2=80=99s no immediate need. Could you explain what the lua-indent-* options do in lua-mode? I tried toggling them but didn=E2=80=99t see any difference between on/off. >>> A far as I understand it, in the `lua-mode' the overall line indentation >>> is computed via subtracting indentation for every `end' in that line, >>> e.g. `end end end' subtracts `lua-indent-level three times from current >>> indent level. >> >> Thanks for the explanation. The attached patch should make end packing >> work now. > > I've tried your latest patch and indeed `end' now pack themselves as in > the lua-mode. Thank you very much! > >>>> Sure. It's a new mode so nothing is really set in stone. Let me know if >>>> you have other suggestions. > > I noticed that the `do' keyword is indented similarly to `then' before > the patch when put on the new line: > > for i=3D1,10 > do > print(i) > end > > I'm not sure if that's a proper way to indent it or not though, but `do' > usually signifies start of the scope, so perhaps it shouldn't be > indented in this case. Fixed in the attached. > There are also some weirdness in semantic navigation, but it's more > likely that I'm just not used to new ts-backed navigation yet. I=E2=80=99m sure there is room for improvement here too. Suggestions welcom= e. > Thanks for your work on lua-ts-mode, it's much more snappy editing > experience now! Glad to hear it. > If you're willing to dig into some (pretty crazy) involved examples, I > can send here some really convoluted nested anonymous functions that > currently are indented in a weird way in both modes. Neither does it > exactly right in my opiion, but I also don't know if there is the right > way to indent this. I can send these examples later this week once I > finish an article I'm working on rightnow. Sure. Whenever you have the time. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Improve-indentation-in-lus-ts-mode-Bug-66159.patch >From 5d41635442d2c1032d015d90527bc5bf6113d291 Mon Sep 17 00:00:00 2001 From: john muhl Date: Sat, 23 Sep 2023 10:49:11 -0500 Subject: [PATCH] Improve indentation in lus-ts-mode (Bug#66159) - Align lines starting with "then" or "do" to the same level as the corresponding "if" or "for" statement. - Align a single-line of "end"s with the beginning of the outermost block being closed. - Anchor indent of the first child in arguments, parameters and tables to the parent and the other children to the first. * lisp/progmodes/lua-ts-mode.el (lua-ts--first-child) (lua-ts--end-indent-offset) (lua-ts--simple-indent-rules): Improve indentation. * test/lisp/progmodes/lua-ts-mode-resources/indent.erts: Add tests. --- lisp/progmodes/lua-ts-mode.el | 27 ++- .../lua-ts-mode-resources/indent.erts | 199 ++++++++++++++++++ 2 files changed, 222 insertions(+), 4 deletions(-) diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index 030a3585158..418d53e0578 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -233,6 +233,17 @@ lua-ts--font-lock-settings '((ERROR) @font-lock-warning-face)) "Tree-sitter font-lock settings for `lua-ts-mode'.") +(defun lua-ts--first-child (node _p _b &rest _) + "Matches if NODE is the first among its siblings." + (= (treesit-node-index node) 1)) + +(defun lua-ts--end-indent-offset (_n _p _b &rest _) + "Calculate indent offset based on `end' count." + (let* ((beg (line-beginning-position)) + (end (line-end-position)) + (count (count-matches "end" beg end))) + (- (* (1- count) lua-ts-indent-offset)))) + (defvar lua-ts--simple-indent-rules `((lua ((parent-is "chunk") column-0 0) @@ -240,9 +251,11 @@ lua-ts--simple-indent-rules ((parent-is "block") parent-bol 0) ((node-is "}") parent-bol 0) ((node-is ")") parent-bol 0) + ((node-is "do") standalone-parent 0) + ((node-is "then") standalone-parent 0) ((node-is "else_statement") parent-bol 0) ((node-is "elseif_statement") parent-bol 0) - ((node-is "end") parent-bol 0) + ((node-is "end") parent-bol lua-ts--end-indent-offset) ((node-is "until") parent-bol 0) ((parent-is "for_statement") parent-bol lua-ts-indent-offset) ((parent-is "function_declaration") parent-bol lua-ts-indent-offset) @@ -251,9 +264,15 @@ lua-ts--simple-indent-rules ((parent-is "else_statement") parent-bol lua-ts-indent-offset) ((parent-is "repeat_statement") parent-bol lua-ts-indent-offset) ((parent-is "while_statement") parent-bol lua-ts-indent-offset) - ((parent-is "table_constructor") parent-bol lua-ts-indent-offset) - ((parent-is "arguments") parent-bol lua-ts-indent-offset) - ((parent-is "parameters") parent-bol lua-ts-indent-offset) + ((and (parent-is "table_constructor") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "table_constructor") (nth-sibling 1) 0) + ((and (parent-is "arguments") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "arguments") (nth-sibling 1) 0) + ((and (parent-is "parameters") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "parameters") (nth-sibling 1) 0) ((parent-is "ERROR") no-indent 0)))) (defvar lua-ts--syntax-table diff --git a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts index 040225c8580..a36a933e640 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts @@ -32,6 +32,22 @@ f({ ;(function() return false )() + +function foo (e) + if e == nil + then return 1000 + else return e + end +end + +function foo (e) + if e == nil + then + return 1000 + else + return e + end +end =-= print( 0, @@ -57,6 +73,22 @@ f({ ;(function() return false )() + +function foo (e) + if e == nil + then return 1000 + else return e + end +end + +function foo (e) + if e == nil + then + return 1000 + else + return e + end +end =-=-= Name: Argument Indent @@ -77,6 +109,13 @@ cost = 2, length = 8, parallelism = 4, }) + +fn(1, +2, + 3) + +fn(1, 2, +3) =-= function h( string, @@ -93,6 +132,13 @@ local p = h( length = 8, parallelism = 4, }) + +fn(1, + 2, + 3) + +fn(1, 2, + 3) =-=-= Name: Continuation Indent @@ -130,10 +176,20 @@ for k, v in pairs({}) do print(k, v) end +for i=1,10 + do + print(i) +end + while n < 10 do n = n + 1 end +while n < 10 + do + n = n + 1 +end + repeat z = z * 2 until z > 12 @@ -142,11 +198,154 @@ for k, v in pairs({}) do print(k, v) end +for i=1,10 +do + print(i) +end + while n < 10 do n = n + 1 end +while n < 10 +do + n = n + 1 +end + repeat z = z * 2 until z > 12 =-=-= + +Name: Parameter Indent + +=-= +fn(a, +b) end + +fn(a, b, +c) end + +fn( +a, +b +) end +=-= +fn(a, + b) end + +fn(a, b, + c) end + +fn( + a, + b +) end +=-=-= + +Code: + (lambda () + (setq indent-tabs-mode nil) + (setq lua-ts-indent-offset 4) + (lua-ts-mode) + (indent-region (point-min) (point-max))) + +Name: Table Indent + +=-= +local Recipe = { + Floor={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Wall={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Corridor={up={Corridoor=true}, + down={Corridoor=true}, + left={Corridoor=true}, + right={Corridoor=true}} +} + +local Other = { +a = 1, + b = 2, + c = 3, +} +=-= +local Recipe = { + Floor={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Wall={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Corridor={up={Corridoor=true}, + down={Corridoor=true}, + left={Corridoor=true}, + right={Corridoor=true}} +} + +local Other = { + a = 1, + b = 2, + c = 3, +} +=-=-= + +Name: Single Line End + +=-= +function lowest_entropy_cell(world) + local lowest,res=math.huge,nil + for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end end end end + return res or {math.random(w.w),math.random(w.h)} +end + +for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end + end end end +=-= +function lowest_entropy_cell(world) + local lowest,res=math.huge,nil + for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end end end end + return res or {math.random(w.w),math.random(w.h)} +end + +for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end +end end end +=-=-= -- 2.41.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Sep 30 03:53:02 2023 Received: (at 66159) by debbugs.gnu.org; 30 Sep 2023 07:53:03 +0000 Received: from localhost ([127.0.0.1]:57630 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qmUmc-00049m-9h for submit@debbugs.gnu.org; Sat, 30 Sep 2023 03:53:02 -0400 Received: from mout01.posteo.de ([185.67.36.65]:53973) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qmUmY-00049Q-Fu for 66159@debbugs.gnu.org; Sat, 30 Sep 2023 03:53:00 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 2D396240028 for <66159@debbugs.gnu.org>; Sat, 30 Sep 2023 09:52:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1696060357; bh=nI5rH2aFO/Fp5LMPYXqchBilSXsUGTNNWH8f3an5rQU=; h=From:To:Cc:Subject:Autocrypt:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=dZNJsgFj6QLzdmxhVacwzEjR9IDLsRb88KrriMGGpcx0ZgDKV4xLIxVKDs0WHzJZz LrDn6Lbpw1roVR+To3UF1Kme9u/q8smyoo+07oIBqPbjV8lIiIg7nB1iNgusesCU80 VMlnP8mEr+QKSSA7wTa0PPCemMuKAZ1k9WEnT+rg/HNB8pJOSEftY0VtQoaZaWHyyl veO0h13/1H0PQjIVqCMXzxnIm7PGVwWn2pv24Vf//NUlP1nTOzDYb4UQyW4P82bWnj 9e000/eM4e0cFphtIDGYfE2vMvmKJykxBJqmAhFvjIrHZLrp6n+J3o0+vM2sebq9aY 1hXQ0s7lURE4A== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RyKFH5kd8z9rxK; Sat, 30 Sep 2023 09:52:35 +0200 (CEST) From: Philip Kaludercic To: john muhl Subject: Re: bug#66159: 30.0.50; lua-ts-mode semantic indentation problems In-Reply-To: <87il7z5g3g.fsf@pub.pink> (john muhl's message of "Sun, 24 Sep 2023 13:20:23 -0500") References: <87fs36vvxl.fsf@gmail.com> <87v8bz3905.fsf@pub.pink> <878r8vwm9v.fsf@gmail.com> <87il7z5g3g.fsf@pub.pink> Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM Date: Sat, 30 Sep 2023 07:52:34 +0000 Message-ID: <8734ywkshp.fsf@posteo.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 66159 Cc: Andrey Listopadov , 66159@debbugs.gnu.org, Eli Zaretskii X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) john muhl writes: > Eli Zaretskii writes: > >>> > Another thing that bothers me is that I prefer Gassanenko-style packi= ng >>> > of `end' keywords so that they vertically align with the scope of the >>> > opened block, as it saves so much vertical space and is easier for me= to >>> > read, but lua-ts-mode moves it to the latest innermost indentation >>> > level, as opposed to the outermost depending on the count of ends in = the >>> > line itself: >>>=20 >>> I don't see any reason not to support that style but I'm not sure how to >>> do it. A patch would be welcome but I'll try to figure it out sometime. >> >> Maybe introduce indentation styles into lua-ts-mode, like CC Mode and >> c-ts-mode have? > > I=E2=80=99ll have a look at what the c-ts-mode styles do and see what mig= ht be > applicable. In this case the changes can be accommodated by default. > > Andrey Listopadov writes: > >> Thanks! The patch seems to work as I would expect for most cases. >> >>> I don't see any reason not to support that style but I'm not sure how to >>> do it. A patch would be welcome but I'll try to figure it out sometime. >> >> A far as I understand it, in the `lua-mode' the overall line indentation >> is computed via subtracting indentation for every `end' in that line, >> e.g. `end end end' subtracts `lua-indent-level three times from current >> indent level. > > Thanks for the explanation. The attached patch should make end packing > work now. > >>> Sure. It's a new mode so nothing is really set in stone. Let me know if >>> you have other suggestions. >> >> I also noticed that `lua-ts-inferior-lua` for some reason starts itself >> in a new frame instead of just a new window. I haven't seen this >> behavior with other inferior-*-modes, and the `lua-start-process' >> function from `lua-mode' doesn't spawn a new frame either. >> >> Looking at the code, it seems that it was a deliberate choice, as I see >> the use of `display-buffer-pop-up-frame' in the `display-buffer' ACTION >> arg. > > It did use a window originally but I was asked to change it: > >>> + (pop-to-buffer buffer))) >> >> I believe that `display-buffer-pop-up-frame' is the preferred alternative >> to `pop-to-buffer' these days. > > Maybe I misunderstood and it was only about not using =E2=80=98pop-to-buf= fer=E2=80=99 > and should have been =E2=80=98display-buffer-pop-up-window=E2=80=99. CC= =E2=80=99d Philip for > clarification. Yes, you are right, I meant `display-buffer-pop-up-window'. > If you customize where you want it with =E2=80=98display-buffer-alist=E2= =80=99 that > should be respected. From debbugs-submit-bounces@debbugs.gnu.org Sat Sep 30 06:29:14 2023 Received: (at 66159) by debbugs.gnu.org; 30 Sep 2023 10:29:15 +0000 Received: from localhost ([127.0.0.1]:57777 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qmXDm-0003Cc-9s for submit@debbugs.gnu.org; Sat, 30 Sep 2023 06:29:14 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:54273) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qmXDh-0003CC-0y for 66159@debbugs.gnu.org; Sat, 30 Sep 2023 06:29:12 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-406589e5765so18240955e9.0 for <66159@debbugs.gnu.org>; Sat, 30 Sep 2023 03:28:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696069727; x=1696674527; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:from:to:cc:subject:date :message-id:reply-to; bh=gCurS4zaXyxvEZ1hi6Huoux7KN1SeLzg6Cs+9FkxK34=; b=H7QWROJAdy0yTCG5lftDLBC2rvWYxroHKTxyz6Re5UzWi20tAPiuKRUSUyR1wGkv3d +LMEdpLjQOc6zYgosKyvrndedTXmJKWoXFnqPqTfPg9oG0GfVhW+i6qEx/iQ1hl0IytU PXSzoErlWrzD4FQ8iYeyr7QhSkresJy32qmYNlj01H+f94CXSP4wPFRPc2Yi7UJLKbbu 737J3fNlsMLt/oJn/isMyLtPwbSt5e4bW4pnRoeUxmuwgrUSxSz8lgvoKi0gq79rbssl oss9Fg7IogM4iu9bqot19PixBZLjON2MOEBHr0KFHjr/cMDX/PwYDMMb09ihPziaF8oB 7e2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696069727; x=1696674527; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=gCurS4zaXyxvEZ1hi6Huoux7KN1SeLzg6Cs+9FkxK34=; b=EdZNHzN1UQgY4OZ92Tsx+xVBnbELb6sxCAKL6JN6zkf13Qvt7UmU8B5NC1Nj0BE7fX 47nc+7O8wVgHQJKt0frUGrwTplcu0dvF0h0kjY2ywLjDr+7+LR6rbL8Uy59XkLm5aRWK ZC0Pl3ITjpez9OLGsx6qsWhEU3yjmA+7n+GwthNRYQhSLFMrpxdKWClTIQR2SW5MB4j+ Hrm/rAkeuuEqY4OsnxOwbzwo9Fxq19KSkTwzLEGeJsG882nUOWBMDyNrvrzjRta86my2 3AgnbYFffdqBAbIJx0lcPjJLvdl9Vk1zYTQ2PWoWdOWuk7NhCgu7HfgaNe1fhSgP+BqU LSLw== X-Gm-Message-State: AOJu0Yw1w5BgLndpt8mMRGaHm0Ky1vMSpP/Ce5OEn3NtJXId7cH/s65I hkLpYyOOfgwvgQHGSyuaGkY= X-Google-Smtp-Source: AGHT+IHoYmL3IyAf+e0s+g+RzpJHV2GNklYYGIx7txcWXttVu83S+bPp8BGuouwHu32WyhKTd9V13Q== X-Received: by 2002:adf:f38c:0:b0:31f:f91c:d872 with SMTP id m12-20020adff38c000000b0031ff91cd872mr6190689wro.19.1696069727051; Sat, 30 Sep 2023 03:28:47 -0700 (PDT) Received: from toolbox.smtp.gmail.com (kotobank.ch. [195.154.83.132]) by smtp.gmail.com with ESMTPSA id 11-20020a056000156b00b0032485046055sm5533949wrz.5.2023.09.30.03.28.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 03:28:46 -0700 (PDT) References: <87fs36vvxl.fsf@gmail.com> <87v8bz3905.fsf@pub.pink> <878r8vwm9v.fsf@gmail.com> <87il7z5g3g.fsf@pub.pink> <87lecs4ttm.fsf@gmail.com> <87fs302oz3.fsf@pub.pink> User-agent: mu4e 1.8.11; emacs 30.0.50 From: Andrey Listopadov To: john muhl Subject: Re: bug#66159: 30.0.50; lua-ts-mode semantic indentation problems Date: Sat, 30 Sep 2023 12:59:28 +0300 In-reply-to: <87fs302oz3.fsf@pub.pink> Message-ID: <87wmw83qg2.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159 Cc: 66159@debbugs.gnu.org, Philip Kaludercic , Eli Zaretskii X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) john muhl writes: > I agree there=E2=80=99s no immediate need. > > Could you explain what the lua-indent-* options do in lua-mode? I tried > toggling them but didn=E2=80=99t see any difference between on/off. I don't really know it myself, sorry. There seem to be some specifics regarding how the content inside parenthesis is indented, but I'm not using these either. >> There are also some weirdness in semantic navigation, but it's more >> likely that I'm just not used to new ts-backed navigation yet. > > I=E2=80=99m sure there is room for improvement here too. Suggestions welc= ome. Here are a few examples. the =E2=96=88 represents the point: =E2=96=88(function (x) return x + 1 end)(41) Pressing C-M-f (forward-sexp) puts the point here: (function (x)=E2=96=88return x + 1 end)(41) I would expect it to go over the whole parenthesized expression: (function (x) return x + 1 end)=E2=96=88(41) Another weird thing here: function foo (x) if false then print "foo" elseif true then print "bar" end end=E2=96=88 Pressing C-M-b (backward-sexp) puts the point here: function foo (x) =E2=96=88if false then print "foo" elseif true then print "bar" end end I would expect it to go before the `function' instead: =E2=96=88function foo (x) if false then print "foo" elseif true then print "bar" end end >> If you're willing to dig into some (pretty crazy) involved examples, I >> can send here some really convoluted nested anonymous functions that >> currently are indented in a weird way in both modes. Neither does it >> exactly right in my opiion, but I also don't know if there is the right >> way to indent this. I can send these examples later this week once I >> finish an article I'm working on rightnow. > > Sure. Whenever you have the time. I've tried a couple of Lua formatters available, and as far as I can see, most of them indent my code in a weird way too, so perhaps it's not really a problem, although I'm not sure. For example, here's a piece of code that implements an iterator wrapper with anonymous functions only: 1 function partitioning (n, collect) 2 return function (iterator) 3 return function (...) 4 return ( 5 function (next1, ...) 6 local count, arr, last =3D 0, {} 7 return (function (f, ...) 8 return (function (i, ...) return i(i, ...) end)( 9 function (i, ...) 10 return f(function (x, ...) 11 return i(i, ...)(x, ...) 12 end, ...) 13 end) 14 end)(function (step) 15 return function(iterable, ...) 16 return (function (recur, iterable, ...) 17 if nil ~=3D ... then 18 if n-1 =3D=3D count then 19 local arr1, count1 =3D arr, count 20 arr, count =3D {}, 0 21 return (function (...) 22 last =3D ... 23 return ... 24 end)(collect(arr1, count1+1, ...= )) 25 else 26 count =3D count + 1 27 return recur(iterable, 28 (function (...) 29 last =3D ... 30 return ... 31 end)(collect(arr, c= ount, ...))) 32 end 33 elseif count ~=3D 0 then 34 count =3D 0 35 return last, arr 36 end 37 end)(step, iterable, next1(iterable, ...)) 38 end 39 end), ... 40 end)(iterator(...)) 41 end 42 end 43 end Here are the lines I find strange. First, the Immediately Invoked Function Expression (IIFE) indentation is all over the place: 8 return (function (i, ...) return i(i, ...) end)( 9 function (i, ...) 10 return f(function (x, ...) 11 return i(i, ...)(x, ...) 12 end, ...) 13 end) The I would expect the inner IIFE to be indented like this: 8 return (function (i, ...) return i(i, ...) end)( 9 function (i, ...) 10 return f(function (x, ...) 11 return i(i, ...)(x, ...) 12 end, ...) 13 end) Another strange snippet: 21 return (function (...) 22 last =3D ... 23 return ... 24 end)(collect(arr1, count1+1, ...= )) The `last' and `return' statements are not properly indented to the function's scope. I expected it to be indented like this: 21 return (function (...) 22 last =3D ... 23 return ... 24 end)(collect(arr1, count= 1+1, ...)) And, weirdly, enough, a bit further in the code there's a similar expression, but it is indented correctly: 27 return recur(iterable, 28 (function (...) 29 last =3D ... 30 return ... 31 end)(collect(arr, c= ount, ...))) I know, that this code is convoluted, and probably no one writes like this, it was done on purpose for an article about the power of anonymous functions, so perhaps it isn't really a problem for most Lua programmers. But it makes reading code a bit harder in rare cases like this. I have more examples in the article, feel free to grab them if you need code snippets for testing: https://andreyor.st/posts/2023-09-26-iterator-based-transducers-in-lua/ Other than that, and the navigation issues I've mentioned above, the mode works solidly. I've also noticed that some of the `lua-mode' default shortcuts are missing, like `C-c C-f' (lua-search-documentation) and `C-c C-l' (lua-send-buffer), but these may be out of the scope of this module, so let me know if I should just define these myself. Thanks! -- Andrey Listopadov From debbugs-submit-bounces@debbugs.gnu.org Sun Oct 01 04:09:00 2023 Received: (at control) by debbugs.gnu.org; 1 Oct 2023 08:09:00 +0000 Received: from localhost ([127.0.0.1]:60451 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qmrVc-0002NO-8y for submit@debbugs.gnu.org; Sun, 01 Oct 2023 04:09:00 -0400 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]:46570) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qmrVa-0002N8-Ia for control@debbugs.gnu.org; Sun, 01 Oct 2023 04:08:58 -0400 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-503397ee920so23679419e87.1 for ; Sun, 01 Oct 2023 01:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696147717; x=1696752517; darn=debbugs.gnu.org; h=to:subject:message-id:date:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=AbRSWO9lWsSTnzGGo/EqH6Nlo//YGfVEbo+94Hwfn7c=; b=AH+yx0ColMMNF9T3Ob+cYfa1v6e9RLe53QQIW+v2KVrA3mIBFozMb2iwGJImnEf3ns nmZz2Qv0xJ4mywH+/W+ylLLjx1vmHPuSaSAp8fOXSifxyvFxsuk75MDyyXD+VAQllgFM whTaWNEFbSy8Oto1WWZVFAYBOhm3v6O1BfBQ3LfLfKjcUcF6reqqYLb5o7YE5Wenag0d iRrM1gBJP4UVNjRBxJvAe5JX+WpgWGWaP5yQke4uZPjNmASMwUPRLCg+HGkmoiTtchJy AprL/HKxdg5EaowJ3/ml3vgkaE62ncVMWPs/kYQGEcmlSz6qj3ELJLvXNqx7zNkC98ig JMSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696147717; x=1696752517; h=to:subject:message-id:date:mime-version:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=AbRSWO9lWsSTnzGGo/EqH6Nlo//YGfVEbo+94Hwfn7c=; b=gRbit8N7Ln9Ca2GgDhNbqavFfex0fQePB8ZGBAt0lQeNaCn31ytROPq7yqqy6GkbHz oBt+GZTkUZcfr073U8y9P7VPL5U0Mt9J/sqmo2/9E4+HgcBPnKe05F/eXBwlw72tqOPB eRiJCE3nPk//sP+I/RiNLY7s0+gudz8TUqyn7Lp3CRzgfOR3RYO+XbIwwli+7G0bHWOs gsa5yJryhBwOS+h6tIIaWYcRE1J/zVV77GbpDB7f919ZzpELJCEd7213GJwPdCLQ81JZ 4b8LCvn0OUFhr1nIC7jGIFqVr9A7fBa9JdW9tckNeKlwLKsEaTQisePQiIAPMqQfX7fo 3XXQ== X-Gm-Message-State: AOJu0YwpKZC2YL6sVVS8kS25w3Eofh1lpkdR4gElY8rRbbPgNI4I+vFO hS4taz0Om1D72enBcA3SVLKrD6U2JHAGPyZkppnBjqiS X-Google-Smtp-Source: AGHT+IGCME194VZNVhKBd24seqUccbQ28djilGGpleanEIh0bSdHE5nzu9UMfBPGZ+RTgsAxIwIE4se1W2Uqw7eVoQo= X-Received: by 2002:ac2:58f7:0:b0:500:8443:744a with SMTP id v23-20020ac258f7000000b005008443744amr6700933lfo.7.1696147716742; Sun, 01 Oct 2023 01:08:36 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sun, 1 Oct 2023 01:08:36 -0700 From: Stefan Kangas MIME-Version: 1.0 Date: Sun, 1 Oct 2023 01:08:36 -0700 Message-ID: Subject: control message for bug #66159 To: control@debbugs.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) tags 66159 + patch quit From debbugs-submit-bounces@debbugs.gnu.org Tue Oct 03 01:12:28 2023 Received: (at 66159) by debbugs.gnu.org; 3 Oct 2023 05:12:28 +0000 Received: from localhost ([127.0.0.1]:38479 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qnXhr-0004qG-Ax for submit@debbugs.gnu.org; Tue, 03 Oct 2023 01:12:28 -0400 Received: from out-204.mta1.migadu.com ([95.215.58.204]:19471) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qnXho-0004q5-K0 for 66159@debbugs.gnu.org; Tue, 03 Oct 2023 01:12:26 -0400 References: <87fs36vvxl.fsf@gmail.com> <87v8bz3905.fsf@pub.pink> <878r8vwm9v.fsf@gmail.com> <87il7z5g3g.fsf@pub.pink> <87lecs4ttm.fsf@gmail.com> <87fs302oz3.fsf@pub.pink> <87wmw83qg2.fsf@gmail.com> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1696309925; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=e0opTcAY2zSXggaP+F3S/Ve8Zx1PYiUZsdIdjcL8IfU=; b=zK0BQ6nTQTdN5VS+LJENZAba0aOeXlmAUhfkCvtzsqLCxAhHVh4nyXSPhCxAefgsetzEDB 4uzjPDxwlE2ngWvb/XGME2c+ycZAGH4uWiXxZkgR9Ks0Vt9LORqG1iptJsBvAQ9Uxev/++ Ja2DU+0gc3xlLvRyPCQJlCk5HtjzQ/Q= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: john muhl To: Andrey Listopadov Subject: Re: bug#66159: 30.0.50; lua-ts-mode semantic indentation problems Date: Sat, 30 Sep 2023 08:57:06 -0500 In-reply-to: <87wmw83qg2.fsf@gmail.com> Message-ID: <874jj847dr.fsf@pub.pink> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Flow: FLOW_OUT X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159 Cc: 66159@debbugs.gnu.org, Eli Zaretskii X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Andrey Listopadov writes: > john muhl writes: > >> I agree there=E2=80=99s no immediate need. >> >> Could you explain what the lua-indent-* options do in lua-mode? I tried >> toggling them but didn=E2=80=99t see any difference between on/off. > > I don't really know it myself, sorry. There seem to be some specifics > regarding how the content inside parenthesis is indented, but I'm not > using these either. I found with the explanation of those options. >>> There are also some weirdness in semantic navigation, but it's more >>> likely that I'm just not used to new ts-backed navigation yet. >> >> I=E2=80=99m sure there is room for improvement here too. Suggestions wel= come. > > Here are a few examples. the =E2=96=88 represents the point: Fixed in the attached. >>> If you're willing to dig into some (pretty crazy) involved examples, I >>> can send here some really convoluted nested anonymous functions that >>> currently are indented in a weird way in both modes. Neither does it >>> exactly right in my opiion, but I also don't know if there is the right >>> way to indent this. I can send these examples later this week once I >>> finish an article I'm working on rightnow. >> >> Sure. Whenever you have the time. > > I know, that this code is convoluted, and probably no one writes like > this, it was done on purpose for an article about the power of anonymous > functions, so perhaps it isn't really a problem for most Lua > programmers. But it makes reading code a bit harder in rare cases like > this. I have more examples in the article, feel free to grab them if you > need code snippets for testing: > > https://andreyor.st/posts/2023-09-26-iterator-based-transducers-in-lua/ Thanks. The patch gets pretty close on the partitioning function from your article (the mapping, filtering and taking functions indent correctly now). The trouble is that you end up with a tree like: (return_statement (expression_list (function_call (parenthesized_expression (function_definition (end)))))) with two different indent styles. return (function (f, ...) -- L7 end)(function (step) -- L14 return (function (...) -- L21 end)(collect(arr1, count1+1, ...)) -- L24 Is there some pattern for deciding that I=E2=80=99m missing? > Other than that, and the navigation issues I've mentioned above, the > mode works solidly. I've also noticed that some of the `lua-mode' > default shortcuts are missing, like `C-c C-f' > (lua-search-documentation) The opening a browser to look at the docs approach isn=E2=80=99t very Emacs= -y so didn=E2=80=99t make the cut. Ideally it should integrate with info and/or e= ldoc but I haven=E2=80=99t gotten to it yet. This should get you by in the meant= ime: --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=lua-ts-dap.el Content-Description: lua-ts-documentation-at-point (defun jm~lua-ts-documentation-at-point () "Show documentation of function at point in the Lua manual." (interactive) (save-excursion ;; When point is mid-word `treesit-thing-at-point' may return ;; the parent node of the thing at point. Go to the beginning ;; of the line or word to make sure we have the right thing. (unless (or (bolp) (not (string-match-p "[[:alnum:]]" (char-to-string (char-before))))) (backward-word)) (when-let* ((node (treesit-thing-at-point 'sentence nil)) ((equal "function_call" (treesit-node-type node))) (child (treesit-node-child-by-field-name node "name")) (name (treesit-node-text child t)) (id (if (string-match-p ":" name) (replace-regexp-in-string "^.*:" "file:" name) name)) ((string-match-p (rx-to-string `(: (? "file:") (or ,@lua-ts--builtins))) id))) (browse-url (concat "file:///usr/share/doc/lua/manual.html" "#pdf-" id))))) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > and `C-c C-l' (lua-send-buffer), but these may be out of the scope of > this module, so let me know if I should just define these myself. The attached patch includes lua-ts-send-{buffer,file,region} commands with bindings for: C-c C-n start inferior Lua C-c C-c send buffer C-c C-l send file C-c C-r send region I=E2=80=99ve been using a send-thing but wasn=E2=80=99t sure it=E2=80=99s w= orth including. What do you think? --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=lua-ts-st.el Content-Description: lua-ts-send-thing (defun jm~lua-ts-send-thing (point) "Send thing near POINT to the inferior Lua process." (interactive "d") (when-let* ((node (treesit-node-at point)) (parent (treesit-parent-until node (lambda (p) (string-match-p (rx (or "do_statement" "for_statement" "function_call" "function_declaration" "if_statement" "repeat_statement" "while_statement")) (treesit-node-type p))) t))) (lua-ts-send-region (treesit-node-start parent) (treesit-node-end parent)))) --=-=-= Content-Type: text/plain It looks at the tree around point and tries to find something to eval; e.g. function fun[1](n) if n > 1 th[2]en print(1) else p[3]rint(0) end end Point at [1] sends the function, [2] the if statement, [3] the print statement. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Various-improvements-in-lus-ts-mode-Bug-66159.patch >From f746dc8bcbe70cccb6d810cfa0e6480d7d6a752a Mon Sep 17 00:00:00 2001 From: john muhl Date: Sat, 23 Sep 2023 10:49:11 -0500 Subject: [PATCH] Various improvements in lus-ts-mode (Bug#66159) * lisp/progmodes/lua-ts-mode.el (lua-ts--first-child) (lua-ts--end-indent-offset) (lua-ts--simple-indent-rules): Improve indentation. (lua-ts-inferior--write-history) (lua-ts-inferior-lua): Improve inferior Lua interaction. (lua-ts-mode-map): Add keymap. (lua-ts-mode-menu): Add menu. (lua-ts-mode): Add mode map and improve sexp navigation. (lua-ts-send-buffer) (lua-ts-send-file) (lua-ts-send-line) (lua-ts-send-region) (lua-ts-show-process-buffer) (lua-ts-hide-process-buffer) (lua-ts-kill-process): New functions. (lua-ts-mode-hook) (lua-ts-inferior-prompt-regexp) (lua-ts-inferior-prompt) (lua-ts-inferior-prompt-continue) (lua-ts-inferior-history): New variables. --- lisp/progmodes/lua-ts-mode.el | 207 ++++++++++++++++-- .../lua-ts-mode-resources/indent.erts | 199 +++++++++++++++++ .../lua-ts-mode-resources/movement.erts | 56 +++++ 3 files changed, 438 insertions(+), 24 deletions(-) diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index 030a3585158..f3fb48ee18a 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -48,6 +48,15 @@ lua-ts :prefix "lua-ts-" :group 'languages) +(defcustom lua-ts-mode-hook nil + "Hook run after entering `lua-ts-mode'." + :type 'hook + :options '(flymake-mode + hs-minor-mode + outline-minor-mode) + :group 'lua-ts + :version "30.1") + (defcustom lua-ts-indent-offset 4 "Number of spaces for each indentation step in `lua-ts-mode'." :type 'natnum @@ -86,9 +95,22 @@ lua-ts-inferior-startfile :group 'lua-ts :version "30.1") -(defcustom lua-ts-inferior-prompt-regexp "^>>?[[:blank:]]" - "Regular expression matching the prompt of the inferior Lua process." - :type 'regexp +(defcustom lua-ts-inferior-prompt ">" + "The prompt of the inferior Lua process." + :type 'string + :group 'lua-ts + :version "30.1") + +(defcustom lua-ts-inferior-prompt-continue ">>" + "The continuation prompt of the inferior Lua process." + :type 'string + :group 'lua-ts + :version "30.1") + +(defcustom lua-ts-inferior-history nil + "File used to save command history of the inferior Lua process." + :type '(choice (const nil) file) + :safe 'string-or-null-p :group 'lua-ts :version "30.1") @@ -233,27 +255,65 @@ lua-ts--font-lock-settings '((ERROR) @font-lock-warning-face)) "Tree-sitter font-lock settings for `lua-ts-mode'.") +(defun lua-ts--first-child (node _p _b &rest _) + "Matches if NODE is the first among its siblings." + (= (treesit-node-index node) 1)) + +(defun lua-ts--end-indent-offset (_n _p _b &rest _) + "Calculate indent offset based on `end' count." + (let* ((beg (line-beginning-position)) + (end (line-end-position)) + (count (count-matches "end" beg end))) + (- (* (1- count) lua-ts-indent-offset)))) + (defvar lua-ts--simple-indent-rules `((lua + ((n-p-gp "end" "function_definition" "arguments") + parent 0) + ((n-p-gp "end" "function_definition" "parenthesized_expression") + parent 0) + ((and (n-p-gp "block" "function_definition" "arguments") + (lambda (_n parent &rest _) + (save-excursion + (goto-char (treesit-node-start parent)) + (backward-char 2) + (not (looking-at ")"))))) + parent lua-ts-indent-offset) + ((and (n-p-gp "block" "function_definition" "parenthesized_expression") + (lambda (node _p bol &rest _) + (equal "assignment_statement" + (treesit-node-type + (treesit-node-first-child-for-pos node bol))))) + parent lua-ts-indent-offset) ((parent-is "chunk") column-0 0) ((node-is "comment_end") column-0 0) ((parent-is "block") parent-bol 0) ((node-is "}") parent-bol 0) ((node-is ")") parent-bol 0) + ((node-is "do") standalone-parent 0) + ((node-is "then") standalone-parent 0) ((node-is "else_statement") parent-bol 0) ((node-is "elseif_statement") parent-bol 0) - ((node-is "end") parent-bol 0) + ((node-is "end") parent-bol lua-ts--end-indent-offset) ((node-is "until") parent-bol 0) ((parent-is "for_statement") parent-bol lua-ts-indent-offset) ((parent-is "function_declaration") parent-bol lua-ts-indent-offset) - ((parent-is "function_definition") parent-bol lua-ts-indent-offset) + ((parent-is "function_definition") standalone-parent lua-ts-indent-offset) + ((parent-is "parenthesized_expression") + standalone-parent lua-ts-indent-offset) ((parent-is "if_statement") parent-bol lua-ts-indent-offset) ((parent-is "else_statement") parent-bol lua-ts-indent-offset) ((parent-is "repeat_statement") parent-bol lua-ts-indent-offset) ((parent-is "while_statement") parent-bol lua-ts-indent-offset) - ((parent-is "table_constructor") parent-bol lua-ts-indent-offset) - ((parent-is "arguments") parent-bol lua-ts-indent-offset) - ((parent-is "parameters") parent-bol lua-ts-indent-offset) + ((and (parent-is "table_constructor") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "table_constructor") (nth-sibling 1) 0) + ((and (parent-is "arguments") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "arguments") (nth-sibling 1) 0) + ((and (parent-is "parameters") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "parameters") (nth-sibling 1) 0) ((parent-is "ERROR") no-indent 0)))) (defvar lua-ts--syntax-table @@ -348,30 +408,127 @@ lua-ts-flymake-luacheck (process-send-region lua-ts--flymake-process (point-min) (point-max)) (process-send-eof lua-ts--flymake-process)))) +(defun lua-ts-inferior--write-history (process _event) + "Write history file for inferior Lua PROCESS." + ;; Depending on how the process is killed the buffer may + ;; not be around anymore; e.g. `kill-buffer'. + (when-let* ((buffer (process-buffer process)) + ((buffer-live-p buffer))) + (with-current-buffer buffer (comint-write-input-ring)))) + ;;;###autoload (defun lua-ts-inferior-lua () "Run a Lua interpreter in an inferior process." (interactive) - (let* ((buffer lua-ts-inferior-buffer) - (name (string-replace "*" "" buffer)) - (program lua-ts-inferior-program) - (prompt-regexp lua-ts-inferior-prompt-regexp) - (switches lua-ts-inferior-options) - (startfile lua-ts-inferior-startfile)) - (unless (comint-check-proc buffer) - (set-buffer (apply (function make-comint) name program startfile switches)) - (setq-local comint-input-ignoredups t - comint-prompt-read-only t - comint-prompt-regexp prompt-regexp - comint-use-prompt-regexp t)) - (select-window (display-buffer buffer '((display-buffer-reuse-window - display-buffer-pop-up-frame) - (reusable-frames . t)))))) + (unless (comint-check-proc lua-ts-inferior-buffer) + (apply #'make-comint-in-buffer + (string-replace "*" "" lua-ts-inferior-buffer) + lua-ts-inferior-buffer + lua-ts-inferior-program + lua-ts-inferior-startfile + lua-ts-inferior-options) + (when lua-ts-inferior-history + (set-process-sentinel (get-buffer-process lua-ts-inferior-buffer) + 'lua-ts-inferior--write-history)) + (with-current-buffer lua-ts-inferior-buffer + (setq comint-prompt-regexp (rx-to-string `(: bol + ,lua-ts-inferior-prompt + space))) + (setq-local comint-input-ignoredups t) + (setq-local comint-input-ring-file-name lua-ts-inferior-history) + (setq-local comint-prompt-read-only t) + (setq-local comint-use-prompt-regexp t) + (comint-read-input-ring t) + (add-hook 'comint-preoutput-filter-functions + (lambda (string) + (if (equal string (concat lua-ts-inferior-prompt-continue " ")) + string ; Don't mess with continuation prompts. + (concat + ;; Filter out the extra prompt characters that + ;; accumulate in the output when sending regions + ;; to the inferior process. + (replace-regexp-in-string (rx-to-string + `(: bol + (* ,lua-ts-inferior-prompt + (? ,lua-ts-inferior-prompt) + space) + (group (* nonl)))) + "\\1" string) + ;; Re-add the prompt for the next line. + lua-ts-inferior-prompt " ")))))) + (select-window (display-buffer lua-ts-inferior-buffer + '((display-buffer-reuse-window + display-buffer-pop-up-window) + (reusable-frames . t)))) + (get-buffer-process (current-buffer))) + +(defun lua-ts-send-buffer () + "Send current buffer to the inferior Lua process." + (interactive) + (lua-ts-send-region (point-min) (point-max))) + +(defun lua-ts-send-file (file) + "Send contents of FILE to the inferior Lua process." + (interactive "f") + (with-temp-buffer + (insert-file-contents-literally file) + (lua-ts-send-region (point-min) (point-max)))) + +(defun lua-ts-send-region (beg end) + "Send region between BEG and END to the inferior Lua process." + (interactive "r") + (let ((string (buffer-substring-no-properties beg end)) + (proc-buffer (lua-ts-inferior-lua))) + (comint-send-string proc-buffer "print()") ; Prevent output from + (comint-send-string proc-buffer "\n") ; appearing at prompt. + (comint-send-string proc-buffer string) + (comint-send-string proc-buffer "\n"))) + +(defun lua-ts-show-process-buffer () + "Show the inferior Lua process buffer." + (interactive) + (display-buffer lua-ts-inferior-buffer)) + +(defun lua-ts-hide-process-buffer () + "Hide the inferior Lua process buffer." + (interactive) + (delete-windows-on lua-ts-inferior-buffer)) + +(defun lua-ts-kill-process () + "Kill the inferior Lua process." + (interactive) + (with-current-buffer lua-ts-inferior-buffer + (kill-buffer-and-window))) + +(defvar lua-ts-mode-map + (let ((map (make-sparse-keymap "Lua"))) + (define-key map "\C-c\C-n" 'lua-ts-inferior-lua) + (define-key map "\C-c\C-c" 'lua-ts-send-buffer) + (define-key map "\C-c\C-l" 'lua-ts-send-file) + map) + "Keymap for `lua-ts-mode' buffers.") + +(easy-menu-define lua-ts-mode-menu lua-ts-mode-map + "Menu bar entry for `lua-ts-mode'." + `("Lua" + ["Evaluate Buffer" lua-ts-send-buffer] + ["Evaluate File" lua-ts-send-file] + ["Evaluate Region" lua-ts-send-region] + "--" + ["Start Process" lua-ts-inferior-lua] + ["Show Process Buffer" lua-ts-show-process-buffer] + ["Hide Process Buffer" lua-ts-hide-process-buffer] + ["Kill Process" lua-ts-kill-process] + "--" + ["Customize" (lambda () (interactive) (customize-group "lua-ts"))])) ;;;###autoload (define-derived-mode lua-ts-mode prog-mode "Lua" - "Major mode for editing Lua files, powered by tree-sitter." + "Major mode for editing Lua files, powered by tree-sitter. + +\\{lua-ts-mode-map}" :syntax-table lua-ts--syntax-table + (use-local-map lua-ts-mode-map) (when (treesit-ready-p 'lua) (treesit-parser-create 'lua) @@ -415,7 +572,9 @@ lua-ts-mode "while_statement"))) (sexp ,(rx (or "arguments" "block" + "function_declaration" "parameters" + "parenthesized_expression" "string" "table_constructor"))) (text "comment")))) diff --git a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts index 040225c8580..c407d3400f8 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts @@ -32,6 +32,22 @@ f({ ;(function() return false )() + +function foo (e) + if e == nil + then return 1000 + else return e + end +end + +function foo (e) + if e == nil + then + return 1000 + else + return e + end +end =-= print( 0, @@ -57,6 +73,22 @@ f({ ;(function() return false )() + +function foo (e) + if e == nil + then return 1000 + else return e + end +end + +function foo (e) + if e == nil + then + return 1000 + else + return e + end +end =-=-= Name: Argument Indent @@ -77,6 +109,13 @@ cost = 2, length = 8, parallelism = 4, }) + +fn(1, +2, + 3) + +fn(1, 2, +3) =-= function h( string, @@ -93,6 +132,13 @@ local p = h( length = 8, parallelism = 4, }) + +fn(1, + 2, + 3) + +fn(1, 2, + 3) =-=-= Name: Continuation Indent @@ -130,10 +176,20 @@ for k, v in pairs({}) do print(k, v) end +for i=1,10 + do + print(i) +end + while n < 10 do n = n + 1 end +while n < 10 + do + n = n + 1 +end + repeat z = z * 2 until z > 12 @@ -142,11 +198,154 @@ for k, v in pairs({}) do print(k, v) end +for i=1,10 +do + print(i) +end + while n < 10 do n = n + 1 end +while n < 10 +do + n = n + 1 +end + repeat z = z * 2 until z > 12 =-=-= + +Name: Parameter Indent + +=-= +fn(a, +b) + +fn(a, b, +c) + +fn( +a, +b +) +=-= +fn(a, + b) + +fn(a, b, + c) + +fn( + a, + b +) +=-=-= + +Code: + (lambda () + (setq indent-tabs-mode nil) + (setq lua-ts-indent-offset 4) + (lua-ts-mode) + (indent-region (point-min) (point-max))) + +Name: Table Indent + +=-= +local Recipe = { + Floor={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Wall={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Corridor={up={Corridoor=true}, + down={Corridoor=true}, + left={Corridoor=true}, + right={Corridoor=true}} +} + +local Other = { +a = 1, + b = 2, + c = 3, +} +=-= +local Recipe = { + Floor={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Wall={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Corridor={up={Corridoor=true}, + down={Corridoor=true}, + left={Corridoor=true}, + right={Corridoor=true}} +} + +local Other = { + a = 1, + b = 2, + c = 3, +} +=-=-= + +Name: Single Line End + +=-= +function lowest_entropy_cell(world) + local lowest,res=math.huge,nil + for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end end end end + return res or {math.random(w.w),math.random(w.h)} +end + +for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end + end end end +=-= +function lowest_entropy_cell(world) + local lowest,res=math.huge,nil + for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end end end end + return res or {math.random(w.w),math.random(w.h)} +end + +for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end +end end end +=-=-= diff --git a/test/lisp/progmodes/lua-ts-mode-resources/movement.erts b/test/lisp/progmodes/lua-ts-mode-resources/movement.erts index 770aa23b18d..afebe93de3f 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/movement.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/movement.erts @@ -481,6 +481,34 @@ local t = { 1, 3 }| =-=-= +Name: forward-sexp moves over parenthesized expressions + +=-= +|(function (x) return x + 1 end)(41) +=-= +(function (x) return x + 1 end)|(41) +=-=-= + +Name: forward-sexp moves over function declarations + +=-= +|function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end +=-= +function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end| +=-=-= + Code: (lambda () (lua-ts-mode) @@ -551,3 +579,31 @@ local t = |{ 1, 2, 3 } =-=-= + +Name: backward-sexp moves over parenthesized expressions + +=-= +(function (x) return x + 1 end)|(41) +=-= +|(function (x) return x + 1 end)(41) +=-=-= + +Name: backward-sexp moves over function declarations + +=-= +function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end| +=-= +|function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end +=-=-= -- 2.41.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Oct 03 11:06:55 2023 Received: (at 66159) by debbugs.gnu.org; 3 Oct 2023 15:06:55 +0000 Received: from localhost ([127.0.0.1]:40570 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qngz8-0004xg-Oc for submit@debbugs.gnu.org; Tue, 03 Oct 2023 11:06:55 -0400 Received: from out-209.mta0.migadu.com ([91.218.175.209]:30960) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qngz5-0004xV-L9 for 66159@debbugs.gnu.org; Tue, 03 Oct 2023 11:06:53 -0400 References: <87fs36vvxl.fsf@gmail.com> <87v8bz3905.fsf@pub.pink> <878r8vwm9v.fsf@gmail.com> <87il7z5g3g.fsf@pub.pink> <87lecs4ttm.fsf@gmail.com> <87fs302oz3.fsf@pub.pink> <87wmw83qg2.fsf@gmail.com> <874jj847dr.fsf@pub.pink> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1696345592; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=w73klHk0dX5h/mkusqXhpqdOwflAGIOfn+uQ/ljKEKU=; b=WGWMfXfhxm90vVSYWTMR++x7qVLb22ZBkgnb2smw48E9B6qhyS5Gh3fpkkvtdeKHOekCSn 2/+PiCJtqUmJFizZJQEf5cnGxPL1PWzvaLd54BcSe0Nqapi8T0O/CEfSsUINwP5cl19qxB xc0FtHA6vnQwvkPDiV/rMD27i+apUnI= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: john muhl To: Andrey Listopadov Subject: Re: bug#66159: 30.0.50; lua-ts-mode semantic indentation problems Date: Tue, 03 Oct 2023 10:04:56 -0500 In-reply-to: <874jj847dr.fsf@pub.pink> Message-ID: <87ttr73fuz.fsf@pub.pink> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Flow: FLOW_OUT X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159 Cc: 66159@debbugs.gnu.org, Eli Zaretskii X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain Whoops. Looks like I forgot to update the patch before sending. This one should be better. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Various-improvements-in-lus-ts-mode-Bug-66159.patch >From 4ee42d82557e188537693c3a27b2246ed690c2a6 Mon Sep 17 00:00:00 2001 From: john muhl Date: Sat, 23 Sep 2023 10:49:11 -0500 Subject: [PATCH] Various improvements in lus-ts-mode (Bug#66159) * lisp/progmodes/lua-ts-mode.el (lua-ts--first-child) (lua-ts--end-indent-offset) (lua-ts--simple-indent-rules): Improve indentation. (lua-ts-inferior--write-history) (lua-ts-inferior-lua): Improve inferior Lua interaction. (lua-ts-mode-map): Add keymap. (lua-ts-mode-menu): Add menu. (lua-ts-mode): Add mode map and improve sexp navigation. (lua-ts-send-buffer) (lua-ts-send-file) (lua-ts-send-line) (lua-ts-send-region) (lua-ts-show-process-buffer) (lua-ts-hide-process-buffer) (lua-ts-kill-process): New functions. (lua-ts-mode-hook) (lua-ts-inferior-prompt-regexp) (lua-ts-inferior-prompt) (lua-ts-inferior-prompt-continue) (lua-ts-inferior-history): New variables. --- lisp/progmodes/lua-ts-mode.el | 210 ++++++++++++++++-- .../lua-ts-mode-resources/indent.erts | 199 +++++++++++++++++ .../lua-ts-mode-resources/movement.erts | 56 +++++ 3 files changed, 441 insertions(+), 24 deletions(-) diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index 030a3585158..d1930d9f2b1 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -39,7 +39,9 @@ (require 'rx)) (declare-function treesit-node-child-by-field-name "treesit.c") +(declare-function treesit-node-first-child-for-pos "treesit.c") (declare-function treesit-node-type "treesit.c") +(declare-function treesit-node-start "treesit.c") (declare-function treesit-parser-create "treesit.c") (declare-function treesit-search-subtree "treesit.c") @@ -48,6 +50,15 @@ lua-ts :prefix "lua-ts-" :group 'languages) +(defcustom lua-ts-mode-hook nil + "Hook run after entering `lua-ts-mode'." + :type 'hook + :options '(flymake-mode + hs-minor-mode + outline-minor-mode) + :group 'lua-ts + :version "30.1") + (defcustom lua-ts-indent-offset 4 "Number of spaces for each indentation step in `lua-ts-mode'." :type 'natnum @@ -86,9 +97,22 @@ lua-ts-inferior-startfile :group 'lua-ts :version "30.1") -(defcustom lua-ts-inferior-prompt-regexp "^>>?[[:blank:]]" - "Regular expression matching the prompt of the inferior Lua process." - :type 'regexp +(defcustom lua-ts-inferior-prompt ">" + "The prompt of the inferior Lua process." + :type 'string + :group 'lua-ts + :version "30.1") + +(defcustom lua-ts-inferior-prompt-continue ">>" + "The continuation prompt of the inferior Lua process." + :type 'string + :group 'lua-ts + :version "30.1") + +(defcustom lua-ts-inferior-history nil + "File used to save command history of the inferior Lua process." + :type '(choice (const nil) file) + :safe 'string-or-null-p :group 'lua-ts :version "30.1") @@ -233,27 +257,65 @@ lua-ts--font-lock-settings '((ERROR) @font-lock-warning-face)) "Tree-sitter font-lock settings for `lua-ts-mode'.") +(defun lua-ts--first-child (node _p _b &rest _) + "Matches if NODE is the first among its siblings." + (= (treesit-node-index node) 1)) + +(defun lua-ts--end-indent-offset (_n _p _b &rest _) + "Calculate indent offset based on `end' count." + (let* ((beg (line-beginning-position)) + (end (line-end-position)) + (count (count-matches "end" beg end))) + (- (* (1- count) lua-ts-indent-offset)))) + (defvar lua-ts--simple-indent-rules `((lua + ((n-p-gp "end" "function_definition" "arguments") + parent 0) + ((n-p-gp "end" "function_definition" "parenthesized_expression") + parent 0) + ((and (n-p-gp "block" "function_definition" "arguments") + (lambda (_n parent &rest _) + (save-excursion + (goto-char (treesit-node-start parent)) + (backward-char 2) + (not (looking-at ")"))))) + parent lua-ts-indent-offset) + ((and (n-p-gp "block" "function_definition" "parenthesized_expression") + (lambda (node _p bol &rest _) + (equal "assignment_statement" + (treesit-node-type + (treesit-node-first-child-for-pos node bol))))) + parent lua-ts-indent-offset) ((parent-is "chunk") column-0 0) ((node-is "comment_end") column-0 0) ((parent-is "block") parent-bol 0) ((node-is "}") parent-bol 0) ((node-is ")") parent-bol 0) + ((node-is "do") standalone-parent 0) + ((node-is "then") standalone-parent 0) ((node-is "else_statement") parent-bol 0) ((node-is "elseif_statement") parent-bol 0) - ((node-is "end") parent-bol 0) + ((node-is "end") parent-bol lua-ts--end-indent-offset) ((node-is "until") parent-bol 0) ((parent-is "for_statement") parent-bol lua-ts-indent-offset) ((parent-is "function_declaration") parent-bol lua-ts-indent-offset) - ((parent-is "function_definition") parent-bol lua-ts-indent-offset) + ((parent-is "function_definition") standalone-parent lua-ts-indent-offset) + ((parent-is "parenthesized_expression") + standalone-parent lua-ts-indent-offset) ((parent-is "if_statement") parent-bol lua-ts-indent-offset) ((parent-is "else_statement") parent-bol lua-ts-indent-offset) ((parent-is "repeat_statement") parent-bol lua-ts-indent-offset) ((parent-is "while_statement") parent-bol lua-ts-indent-offset) - ((parent-is "table_constructor") parent-bol lua-ts-indent-offset) - ((parent-is "arguments") parent-bol lua-ts-indent-offset) - ((parent-is "parameters") parent-bol lua-ts-indent-offset) + ((and (parent-is "table_constructor") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "table_constructor") (nth-sibling 1) 0) + ((and (parent-is "arguments") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "arguments") (nth-sibling 1) 0) + ((and (parent-is "parameters") lua-ts--first-child) + parent-bol lua-ts-indent-offset) + ((parent-is "parameters") (nth-sibling 1) 0) ((parent-is "ERROR") no-indent 0)))) (defvar lua-ts--syntax-table @@ -348,30 +410,128 @@ lua-ts-flymake-luacheck (process-send-region lua-ts--flymake-process (point-min) (point-max)) (process-send-eof lua-ts--flymake-process)))) +(defun lua-ts-inferior--write-history (process _event) + "Write history file for inferior Lua PROCESS." + ;; Depending on how the process is killed the buffer may + ;; not be around anymore; e.g. `kill-buffer'. + (when-let* ((buffer (process-buffer process)) + ((buffer-live-p buffer))) + (with-current-buffer buffer (comint-write-input-ring)))) + ;;;###autoload (defun lua-ts-inferior-lua () "Run a Lua interpreter in an inferior process." (interactive) - (let* ((buffer lua-ts-inferior-buffer) - (name (string-replace "*" "" buffer)) - (program lua-ts-inferior-program) - (prompt-regexp lua-ts-inferior-prompt-regexp) - (switches lua-ts-inferior-options) - (startfile lua-ts-inferior-startfile)) - (unless (comint-check-proc buffer) - (set-buffer (apply (function make-comint) name program startfile switches)) - (setq-local comint-input-ignoredups t - comint-prompt-read-only t - comint-prompt-regexp prompt-regexp - comint-use-prompt-regexp t)) - (select-window (display-buffer buffer '((display-buffer-reuse-window - display-buffer-pop-up-frame) - (reusable-frames . t)))))) + (unless (comint-check-proc lua-ts-inferior-buffer) + (apply #'make-comint-in-buffer + (string-replace "*" "" lua-ts-inferior-buffer) + lua-ts-inferior-buffer + lua-ts-inferior-program + lua-ts-inferior-startfile + lua-ts-inferior-options) + (when lua-ts-inferior-history + (set-process-sentinel (get-buffer-process lua-ts-inferior-buffer) + 'lua-ts-inferior--write-history)) + (with-current-buffer lua-ts-inferior-buffer + (setq comint-prompt-regexp (rx-to-string `(: bol + ,lua-ts-inferior-prompt + space))) + (setq-local comint-input-ignoredups t) + (setq-local comint-input-ring-file-name lua-ts-inferior-history) + (setq-local comint-prompt-read-only t) + (setq-local comint-use-prompt-regexp t) + (comint-read-input-ring t) + (add-hook 'comint-preoutput-filter-functions + (lambda (string) + (if (equal string (concat lua-ts-inferior-prompt-continue " ")) + string ; Don't mess with continuation prompts. + (concat + ;; Filter out the extra prompt characters that + ;; accumulate in the output when sending regions + ;; to the inferior process. + (replace-regexp-in-string (rx-to-string + `(: bol + (* ,lua-ts-inferior-prompt + (? ,lua-ts-inferior-prompt) + space) + (group (* nonl)))) + "\\1" string) + ;; Re-add the prompt for the next line. + lua-ts-inferior-prompt " ")))))) + (select-window (display-buffer lua-ts-inferior-buffer + '((display-buffer-reuse-window + display-buffer-pop-up-window) + (reusable-frames . t)))) + (get-buffer-process (current-buffer))) + +(defun lua-ts-send-buffer () + "Send current buffer to the inferior Lua process." + (interactive) + (lua-ts-send-region (point-min) (point-max))) + +(defun lua-ts-send-file (file) + "Send contents of FILE to the inferior Lua process." + (interactive "f") + (with-temp-buffer + (insert-file-contents-literally file) + (lua-ts-send-region (point-min) (point-max)))) + +(defun lua-ts-send-region (beg end) + "Send region between BEG and END to the inferior Lua process." + (interactive "r") + (let ((string (buffer-substring-no-properties beg end)) + (proc-buffer (lua-ts-inferior-lua))) + (comint-send-string proc-buffer "print()") ; Prevent output from + (comint-send-string proc-buffer "\n") ; appearing at prompt. + (comint-send-string proc-buffer string) + (comint-send-string proc-buffer "\n"))) + +(defun lua-ts-show-process-buffer () + "Show the inferior Lua process buffer." + (interactive) + (display-buffer lua-ts-inferior-buffer)) + +(defun lua-ts-hide-process-buffer () + "Hide the inferior Lua process buffer." + (interactive) + (delete-windows-on lua-ts-inferior-buffer)) + +(defun lua-ts-kill-process () + "Kill the inferior Lua process." + (interactive) + (with-current-buffer lua-ts-inferior-buffer + (kill-buffer-and-window))) + +(defvar lua-ts-mode-map + (let ((map (make-sparse-keymap "Lua"))) + (define-key map "\C-c\C-n" 'lua-ts-inferior-lua) + (define-key map "\C-c\C-c" 'lua-ts-send-buffer) + (define-key map "\C-c\C-l" 'lua-ts-send-file) + (define-key map "\C-c\C-r" 'lua-ts-send-region) + map) + "Keymap for `lua-ts-mode' buffers.") + +(easy-menu-define lua-ts-mode-menu lua-ts-mode-map + "Menu bar entry for `lua-ts-mode'." + `("Lua" + ["Evaluate Buffer" lua-ts-send-buffer] + ["Evaluate File" lua-ts-send-file] + ["Evaluate Region" lua-ts-send-region] + "--" + ["Start Process" lua-ts-inferior-lua] + ["Show Process Buffer" lua-ts-show-process-buffer] + ["Hide Process Buffer" lua-ts-hide-process-buffer] + ["Kill Process" lua-ts-kill-process] + "--" + ["Customize" (lambda () (interactive) (customize-group "lua-ts"))])) ;;;###autoload (define-derived-mode lua-ts-mode prog-mode "Lua" - "Major mode for editing Lua files, powered by tree-sitter." + "Major mode for editing Lua files, powered by tree-sitter. + +\\{lua-ts-mode-map}" :syntax-table lua-ts--syntax-table + (use-local-map lua-ts-mode-map) (when (treesit-ready-p 'lua) (treesit-parser-create 'lua) @@ -415,7 +575,9 @@ lua-ts-mode "while_statement"))) (sexp ,(rx (or "arguments" "block" + "function_declaration" "parameters" + "parenthesized_expression" "string" "table_constructor"))) (text "comment")))) diff --git a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts index 040225c8580..c407d3400f8 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts @@ -32,6 +32,22 @@ f({ ;(function() return false )() + +function foo (e) + if e == nil + then return 1000 + else return e + end +end + +function foo (e) + if e == nil + then + return 1000 + else + return e + end +end =-= print( 0, @@ -57,6 +73,22 @@ f({ ;(function() return false )() + +function foo (e) + if e == nil + then return 1000 + else return e + end +end + +function foo (e) + if e == nil + then + return 1000 + else + return e + end +end =-=-= Name: Argument Indent @@ -77,6 +109,13 @@ cost = 2, length = 8, parallelism = 4, }) + +fn(1, +2, + 3) + +fn(1, 2, +3) =-= function h( string, @@ -93,6 +132,13 @@ local p = h( length = 8, parallelism = 4, }) + +fn(1, + 2, + 3) + +fn(1, 2, + 3) =-=-= Name: Continuation Indent @@ -130,10 +176,20 @@ for k, v in pairs({}) do print(k, v) end +for i=1,10 + do + print(i) +end + while n < 10 do n = n + 1 end +while n < 10 + do + n = n + 1 +end + repeat z = z * 2 until z > 12 @@ -142,11 +198,154 @@ for k, v in pairs({}) do print(k, v) end +for i=1,10 +do + print(i) +end + while n < 10 do n = n + 1 end +while n < 10 +do + n = n + 1 +end + repeat z = z * 2 until z > 12 =-=-= + +Name: Parameter Indent + +=-= +fn(a, +b) + +fn(a, b, +c) + +fn( +a, +b +) +=-= +fn(a, + b) + +fn(a, b, + c) + +fn( + a, + b +) +=-=-= + +Code: + (lambda () + (setq indent-tabs-mode nil) + (setq lua-ts-indent-offset 4) + (lua-ts-mode) + (indent-region (point-min) (point-max))) + +Name: Table Indent + +=-= +local Recipe = { + Floor={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Wall={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Corridor={up={Corridoor=true}, + down={Corridoor=true}, + left={Corridoor=true}, + right={Corridoor=true}} +} + +local Other = { +a = 1, + b = 2, + c = 3, +} +=-= +local Recipe = { + Floor={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Wall={up={Floor=true,Wall=true}, + down={Floor=true,Wall=true}, + left={Floor=true,Wall=true}, + right={Floor=true,Wall=true}}, + Corridor={up={Corridoor=true}, + down={Corridoor=true}, + left={Corridoor=true}, + right={Corridoor=true}} +} + +local Other = { + a = 1, + b = 2, + c = 3, +} +=-=-= + +Name: Single Line End + +=-= +function lowest_entropy_cell(world) + local lowest,res=math.huge,nil + for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end end end end + return res or {math.random(w.w),math.random(w.h)} +end + +for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end + end end end +=-= +function lowest_entropy_cell(world) + local lowest,res=math.huge,nil + for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end end end end + return res or {math.random(w.w),math.random(w.h)} +end + +for y=1,world.height do + for x=1,world.width do + local cell=world:get(x,y) + if cell.is_set then + local e=cell_enthropy(cell) + trace(e) + if e <= lowest then + lowest,res=e,{x,y} + end +end end end +=-=-= diff --git a/test/lisp/progmodes/lua-ts-mode-resources/movement.erts b/test/lisp/progmodes/lua-ts-mode-resources/movement.erts index 770aa23b18d..afebe93de3f 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/movement.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/movement.erts @@ -481,6 +481,34 @@ local t = { 1, 3 }| =-=-= +Name: forward-sexp moves over parenthesized expressions + +=-= +|(function (x) return x + 1 end)(41) +=-= +(function (x) return x + 1 end)|(41) +=-=-= + +Name: forward-sexp moves over function declarations + +=-= +|function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end +=-= +function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end| +=-=-= + Code: (lambda () (lua-ts-mode) @@ -551,3 +579,31 @@ local t = |{ 1, 2, 3 } =-=-= + +Name: backward-sexp moves over parenthesized expressions + +=-= +(function (x) return x + 1 end)|(41) +=-= +|(function (x) return x + 1 end)(41) +=-=-= + +Name: backward-sexp moves over function declarations + +=-= +function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end| +=-= +|function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end +=-=-= -- 2.41.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Oct 03 15:17:21 2023 Received: (at 66159) by debbugs.gnu.org; 3 Oct 2023 19:17:21 +0000 Received: from localhost ([127.0.0.1]:40734 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qnktV-00038y-1d for submit@debbugs.gnu.org; Tue, 03 Oct 2023 15:17:21 -0400 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]:42135) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qnktS-00038j-DK for 66159@debbugs.gnu.org; Tue, 03 Oct 2023 15:17:19 -0400 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-9adb9fa7200so33686666b.0 for <66159@debbugs.gnu.org>; Tue, 03 Oct 2023 12:17:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696360615; x=1696965415; darn=debbugs.gnu.org; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=S6bvJntOdMn/0mVsCBHVoUS2pK6DR06EvmCqh7KkpHM=; b=A2wSe1UhDFHbK3ZTULSlT6e8JM1Z93KJpvTsLeZrJkws3V5+9VpCfgZJSlsOIwFJW2 D3+K/Kb3lFYfHewNOG97odh6g4T2yhB3eOnBToYIVqc6krMc2tt9zPoS94d5oZJbZTxn PbH5f6pkd++8DaM7RGB91WUjgO0DzaXiJmlhyquW1qZcQdlGDgmymBqczKlFCmKCbQnF L4dtD1UKnMT4zdUMKhfBdsSC5V7yPWv7XCQyvA1N2FkXtRyDx6IVYp+dCGQ5hR0XEoZu NY6wKGvUrOrAlqa3DodfivWyac1Plr9eUOIYmxRr98kIUcYFhu2CSLtDLB+2HQWD1Cql llsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360615; x=1696965415; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=S6bvJntOdMn/0mVsCBHVoUS2pK6DR06EvmCqh7KkpHM=; b=b8N1kox5Ocrkq4qXX9PMWQyNCWjpJMOsofetGZewfJInZt2avc2qcOFakr5fYvHi3O +EiqLES/vwl9U3DLjulxJ64vzmVqnUwPuKteyDiGvWUEclZ99OqE3SW28mz38FfDQvit uZ2hhWPBFrxpIbt+xFYk2oZKYpIN47kVqKJw5ZBP291Dnns/SncB4Wl66LZljrw657yf Cj7aifo83IwNSk+i6URrRTLTgfSdveAeVitR34QsZEHY0LaPG8yaEzkJM1kwsk/sw1kN XTZdckxZXR37Rs5eZNoq6huEZHEWcxRP9spKzW9Igd+yOVJK9u+7GHqNZ1tAUcnbnwxb RD9w== X-Gm-Message-State: AOJu0YyFTRS32Ik6Pcd7ZCPhboUhaj8kTVTx4UmdNFlDyR+WZlwvYu2n HgRhO4pNBIGFs+/Lnzf8LE4= X-Google-Smtp-Source: AGHT+IGhP4Ue+Kp0b5PiIe10gwx3JxdS4YdVE9H1aCNlB1wBob/RxWAIOxS21//Ef1eIZWXJDe7HlA== X-Received: by 2002:a17:907:7634:b0:9ae:699d:8a31 with SMTP id jy20-20020a170907763400b009ae699d8a31mr143642ejc.33.1696360614832; Tue, 03 Oct 2023 12:16:54 -0700 (PDT) Received: from toolbox.smtp.gmail.com (broadband-90-154-71-4.ip.moscow.rt.ru. [90.154.71.4]) by smtp.gmail.com with ESMTPSA id lg25-20020a170906f89900b00977cad140a8sm1492438ejb.218.2023.10.03.12.16.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:16:54 -0700 (PDT) References: <87fs36vvxl.fsf@gmail.com> <87v8bz3905.fsf@pub.pink> <878r8vwm9v.fsf@gmail.com> <87il7z5g3g.fsf@pub.pink> <87lecs4ttm.fsf@gmail.com> <87fs302oz3.fsf@pub.pink> <87wmw83qg2.fsf@gmail.com> <874jj847dr.fsf@pub.pink> <87ttr73fuz.fsf@pub.pink> User-agent: mu4e 1.8.11; emacs 30.0.50 From: Andrey Listopadov To: john muhl Subject: Re: bug#66159: 30.0.50; lua-ts-mode semantic indentation problems Date: Tue, 03 Oct 2023 22:13:23 +0300 In-reply-to: <87ttr73fuz.fsf@pub.pink> Message-ID: <877co3tt23.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159 Cc: 66159@debbugs.gnu.org, Eli Zaretskii X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) john muhl writes: > Whoops. Looks like I forgot to update the patch before sending. This one > should be better. > > [2. text/x-patch; 0001-Various-improvements-in-lus-ts-mode-Bug-66159.patch]... Thanks! I tried the patch, and it works great! I noticed a small indentation problem: function (...) return (function (x) return x end)(foo(...)) end probably this should be: function (...) return (function (x) return x end)(...) end The movement now works great, thanks. -- Andrey Listopadov From debbugs-submit-bounces@debbugs.gnu.org Fri Oct 06 21:12:43 2023 Received: (at 66159) by debbugs.gnu.org; 7 Oct 2023 01:12:43 +0000 Received: from localhost ([127.0.0.1]:53070 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qovs2-0001BK-8e for submit@debbugs.gnu.org; Fri, 06 Oct 2023 21:12:43 -0400 Received: from out-203.mta1.migadu.com ([2001:41d0:203:375::cb]:18610) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qovry-0001B8-7g for 66159@debbugs.gnu.org; Fri, 06 Oct 2023 21:12:40 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1696641137; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=fsvtABrKfrnY15AmdoY+YAA28UWefy1LzF9Vqv4oWxo=; b=VGn3DI+ORcXAF1V1Vf7tY283Jal1jqF6zaUS7DUA2Vsm71I9Jed0T/PwMyBd2B/TjHSaFP 5SZkqCuSO2PoPh3lh+M7wLXyuCMDJS2B6DEk2soFiHvtttkGb24cfJaQUVyUh3417kII9O w7CA7Hh4ITtIlAKM0OZcPyh5AXq+2Ik= From: john muhl To: 66159@debbugs.gnu.org Subject: [PATCH] Various improvements to lua-ts-mode (Bug#66159) Date: Fri, 06 Oct 2023 14:44:42 -0500 Message-ID: <8734ynz15f.fsf@pub.pink> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Flow: FLOW_OUT X-Spam-Score: 1.1 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Tags: patch Here is a cleaned up patch. A couple of small additions unrelated to this bug are included but I can separate them if anyone prefers. The additions are: - Make lua-ts-mode-hook a defcustom. - Add an option to use a history file for inferior process input. Content analysis details: (1.1 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 1.1 DATE_IN_PAST_03_06 Date: is 3 to 6 hours before Received: date -0.0 SPF_PASS SPF: sender matches SPF record X-Debbugs-Envelope-To: 66159 Cc: Andrey Listopadov X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.1 (/) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Tags: patch Here is a cleaned up patch. A couple of small additions unrelated to this bug are included but I can separate them if anyone prefers. The additions are: - Make lua-ts-mode-hook a defcustom. - Add an option to use a history file for inferior process input. Andrey if you could test this one it=E2=80=99d be appreciated. Thanks for y= our help. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Various-improvements-to-lua-ts-mode-Bug-66159.patch >From 8f128eb7e68e0bafe0a123623e40cd59a062b93f Mon Sep 17 00:00:00 2001 From: john muhl Date: Wed, 4 Oct 2023 20:46:15 -0500 Subject: [PATCH] Various improvements to lua-ts-mode (Bug#66159) * lisp/progmodes/lua-ts-mode.el (lua-ts-mode): Navigate function declarations and parenthesized expressions with *-sexp commands. (lua-ts--simple-indent-rules): Improve indentation rules. (lua-ts-mode-map): Add key bindings and menus. (lua-ts-mode-hook): Make hook available in Customize. (lua-ts-inferior-history): (lua-ts-inferior--write-history): Add option to read/write an input history file. (lua-ts-inferior-lua): (lua-ts-send-buffer): (lua-ts-send-file): (lua-ts-send-region): (lua-ts-inferior-prompt): (lua-ts-inferior-prompt-continue): Support for sending buffer, file or region to the inferior process. (lua-ts-show-process-buffer): (lua-ts-hide-process-buffer): (lua-ts-kill-process): New functions. (lua-ts-inferior-prompt-regexp): Remove option. * test/lisp/progmodes/lua-ts-mode-resources/indent.erts: * test/lisp/progmodes/lua-ts-mode-resources/movement.erts: Add tests. --- lisp/progmodes/lua-ts-mode.el | 296 +++++++- .../lua-ts-mode-resources/indent.erts | 675 +++++++++++++++--- .../lua-ts-mode-resources/movement.erts | 56 ++ 3 files changed, 903 insertions(+), 124 deletions(-) diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index 030a3585158..8b4a60e74bf 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -38,7 +38,11 @@ (require 'cl-lib) (require 'rx)) +(declare-function treesit-induce-sparse-tree "treesit.c") (declare-function treesit-node-child-by-field-name "treesit.c") +(declare-function treesit-node-first-child-for-pos "treesit.c") +(declare-function treesit-node-parent "treesit.c") +(declare-function treesit-node-start "treesit.c") (declare-function treesit-node-type "treesit.c") (declare-function treesit-parser-create "treesit.c") (declare-function treesit-search-subtree "treesit.c") @@ -48,6 +52,15 @@ lua-ts :prefix "lua-ts-" :group 'languages) +(defcustom lua-ts-mode-hook nil + "Hook run after entering `lua-ts-mode'." + :type 'hook + :options '(flymake-mode + hs-minor-mode + outline-minor-mode) + :group 'lua-ts + :version "30.1") + (defcustom lua-ts-indent-offset 4 "Number of spaces for each indentation step in `lua-ts-mode'." :type 'natnum @@ -86,9 +99,24 @@ lua-ts-inferior-startfile :group 'lua-ts :version "30.1") -(defcustom lua-ts-inferior-prompt-regexp "^>>?[[:blank:]]" - "Regular expression matching the prompt of the inferior Lua process." - :type 'regexp +(defcustom lua-ts-inferior-prompt ">" + "Prompt used by the inferior Lua process." + :type 'string + :safe 'stringp + :group 'lua-ts + :version "30.1") + +(defcustom lua-ts-inferior-prompt-continue ">>" + "Continuation prompt used by the inferior Lua process." + :type 'string + :safe 'stringp + :group 'lua-ts + :version "30.1") + +(defcustom lua-ts-inferior-history nil + "File used to save command history of the inferior Lua process." + :type '(choice (const nil) file) + :safe 'string-or-null-p :group 'lua-ts :version "30.1") @@ -235,27 +263,125 @@ lua-ts--font-lock-settings (defvar lua-ts--simple-indent-rules `((lua + ((or (node-is "comment") + (parent-is "comment_content") + (parent-is "string_content") + (node-is "]]")) + no-indent 0) + ((or (node-is "do") + (node-is "then") + (node-is "elseif_statement") + (node-is "else_statement") + (node-is "until") + (node-is ")") + (node-is "}")) + standalone-parent 0) + ((or (and (parent-is "arguments") lua-ts--first-child-matcher) + (and (parent-is "parameters") lua-ts--first-child-matcher) + (and (parent-is "table_constructor") lua-ts--first-child-matcher)) + standalone-parent lua-ts-indent-offset) + ((or (parent-is "arguments") + (parent-is "parameters") + (parent-is "table_constructor")) + (nth-sibling 1) 0) + ((and (n-p-gp "block" "function_definition" "parenthesized_expression") + lua-ts--nested-function-block-matcher + lua-ts--nested-function-block-include-matcher) + parent lua-ts-indent-offset) + ((and (n-p-gp "block" "function_definition" "arguments") + lua-ts--nested-function-argument-matcher) + parent lua-ts-indent-offset) + ((match "function_definition" "parenthesized_expression") + standalone-parent lua-ts-indent-offset) + ((node-is "block") standalone-parent lua-ts-indent-offset) + ((parent-is "block") parent 0) + ((and (node-is "end") lua-ts--end-line-matcher) + standalone-parent lua-ts--end-indent-offset) + ((match "end" "function_declaration") parent 0) + ((and (n-p-gp "end" "function_definition" "parenthesized_expression") + lua-ts--nested-function-end-argument-matcher) + parent 0) + ((and (n-p-gp "end" "function_definition" "parenthesized_expression") + lua-ts--nested-function-block-matcher + lua-ts--nested-function-end-matcher + lua-ts--nested-function-last-function-matcher) + parent 0) + ((n-p-gp "end" "function_definition" "arguments") parent 0) + ((or (match "end" "function_definition") + (node-is "end")) + standalone-parent 0) ((parent-is "chunk") column-0 0) - ((node-is "comment_end") column-0 0) - ((parent-is "block") parent-bol 0) - ((node-is "}") parent-bol 0) - ((node-is ")") parent-bol 0) - ((node-is "else_statement") parent-bol 0) - ((node-is "elseif_statement") parent-bol 0) - ((node-is "end") parent-bol 0) - ((node-is "until") parent-bol 0) - ((parent-is "for_statement") parent-bol lua-ts-indent-offset) - ((parent-is "function_declaration") parent-bol lua-ts-indent-offset) - ((parent-is "function_definition") parent-bol lua-ts-indent-offset) - ((parent-is "if_statement") parent-bol lua-ts-indent-offset) - ((parent-is "else_statement") parent-bol lua-ts-indent-offset) - ((parent-is "repeat_statement") parent-bol lua-ts-indent-offset) - ((parent-is "while_statement") parent-bol lua-ts-indent-offset) - ((parent-is "table_constructor") parent-bol lua-ts-indent-offset) - ((parent-is "arguments") parent-bol lua-ts-indent-offset) - ((parent-is "parameters") parent-bol lua-ts-indent-offset) ((parent-is "ERROR") no-indent 0)))) +(defun lua-ts--end-line-matcher (&rest _) + "Matches if there is more than one `end' on the current line." + (> (lua-ts--end-count) 1)) + +(defun lua-ts--end-indent-offset (&rest _) + "Calculate indent offset based on `end' count." + (- (* (1- (lua-ts--end-count)) lua-ts-indent-offset))) + +(defun lua-ts--end-count () + "Count the number of `end's on the current line." + (count-matches "end" (line-beginning-position) (line-end-position))) + +(defun lua-ts--first-child-matcher (node &rest _) + "Matches if NODE is the first among its siblings." + (= (treesit-node-index node) 1)) + +(defun lua-ts--function-definition-p (node) + "Return t if NODE is a function_definition." + (equal "function_definition" (treesit-node-type node))) + +(defun lua-ts--g-g-g-parent (node) + "Return the great-great-grand-parent of NODE." + (let* ((parent (treesit-node-parent node)) + (g-parent (treesit-node-parent parent)) + (g-g-parent (treesit-node-parent g-parent))) + (treesit-node-parent g-g-parent))) + +(defun lua-ts--nested-function-argument-matcher (node &rest _) + "Matches if NODE is in a nested function argument." + (save-excursion + (goto-char (treesit-node-start node)) + (treesit-beginning-of-defun) + (backward-char 2) + (not (looking-at ")(")))) + +(defun lua-ts--nested-function-block-matcher (node &rest _) + "Matches if NODE is in a nested function block." + (let* ((g-g-g-parent (lua-ts--g-g-g-parent node)) + (g-g-g-type (treesit-node-type g-g-g-parent))) + (not (equal g-g-g-type "chunk")))) + +(defun lua-ts--nested-function-block-include-matcher (node _p bol &rest _) + "Matches if NODE's child at BOL is not another block." + (let* ((child (treesit-node-first-child-for-pos node bol)) + (child-type (treesit-node-type child)) + (g-g-g-type (treesit-node-type (lua-ts--g-g-g-parent node)))) + (or (equal child-type "assignment_statement") + (and (equal child-type "return_statement") + (or (equal g-g-g-type "arguments") + (and (equal g-g-g-type "expression_list") + (not (treesit-search-subtree child "function_call")))))))) + +(defun lua-ts--nested-function-end-matcher (node &rest _) + "Matches if NODE is the `end' of a nested function." + (save-excursion + (goto-char (treesit-node-start node)) + (treesit-beginning-of-defun) + (looking-at "function[[:space:]]*"))) + +(defun lua-ts--nested-function-end-argument-matcher (node &rest _) + "Matches if great-great-grandparent of NODE is arguments." + (equal "arguments" (treesit-node-type (lua-ts--g-g-g-parent node)))) + +(defun lua-ts--nested-function-last-function-matcher (_n parent &rest _) + "Matches if PARENT is the last nested function." + (let ((sparse-tree + (treesit-induce-sparse-tree parent #'lua-ts--function-definition-p))) + (= 1 (length (cadr sparse-tree))))) + (defvar lua-ts--syntax-table (let ((table (make-syntax-table))) (modify-syntax-entry ?+ "." table) @@ -352,26 +478,124 @@ lua-ts-flymake-luacheck (defun lua-ts-inferior-lua () "Run a Lua interpreter in an inferior process." (interactive) - (let* ((buffer lua-ts-inferior-buffer) - (name (string-replace "*" "" buffer)) - (program lua-ts-inferior-program) - (prompt-regexp lua-ts-inferior-prompt-regexp) - (switches lua-ts-inferior-options) - (startfile lua-ts-inferior-startfile)) - (unless (comint-check-proc buffer) - (set-buffer (apply (function make-comint) name program startfile switches)) + (unless (comint-check-proc lua-ts-inferior-buffer) + (apply #'make-comint-in-buffer + (string-replace "*" "" lua-ts-inferior-buffer) + lua-ts-inferior-buffer + lua-ts-inferior-program + lua-ts-inferior-startfile + lua-ts-inferior-options) + (when lua-ts-inferior-history + (set-process-sentinel (get-buffer-process lua-ts-inferior-buffer) + 'lua-ts-inferior--write-history)) + (with-current-buffer lua-ts-inferior-buffer (setq-local comint-input-ignoredups t + comint-input-ring-file-name lua-ts-inferior-history + comint-use-prompt-regexp t comint-prompt-read-only t - comint-prompt-regexp prompt-regexp - comint-use-prompt-regexp t)) - (select-window (display-buffer buffer '((display-buffer-reuse-window - display-buffer-pop-up-frame) - (reusable-frames . t)))))) + comint-prompt-regexp (rx-to-string `(: bol + ,lua-ts-inferior-prompt + (1+ space)))) + (comint-read-input-ring t) + (add-hook 'comint-preoutput-filter-functions + (lambda (string) + (if (equal string (concat lua-ts-inferior-prompt-continue " ")) + string ; Don't mess with continuation prompts. + (concat + ;; Filter out the extra prompt characters that + ;; accumulate in the output when sending regions + ;; to the inferior process. + (replace-regexp-in-string (rx-to-string + `(: bol + (* ,lua-ts-inferior-prompt + (? ,lua-ts-inferior-prompt) + (1+ space)) + (group (* nonl)))) + "\\1" string) + ;; Re-add the prompt for the next line. + lua-ts-inferior-prompt " ")))))) + (select-window (display-buffer lua-ts-inferior-buffer + '((display-buffer-reuse-window + display-buffer-pop-up-frame) + (reusable-frames . t)))) + (get-buffer-process (current-buffer))) + +(defun lua-ts-send-buffer () + "Send current buffer to the inferior Lua process." + (interactive) + (lua-ts-send-region (point-min) (point-max))) + +(defun lua-ts-send-file (file) + "Send contents of FILE to the inferior Lua process." + (interactive "f") + (with-temp-buffer + (insert-file-contents-literally file) + (lua-ts-send-region (point-min) (point-max)))) + +(defun lua-ts-send-region (beg end) + "Send region between BEG and END to the inferior Lua process." + (interactive "r") + (let ((string (buffer-substring-no-properties beg end)) + (proc-buffer (lua-ts-inferior-lua))) + (comint-send-string proc-buffer "print()") ; Prevent output from + (comint-send-string proc-buffer "\n") ; appearing at prompt. + (comint-send-string proc-buffer string) + (comint-send-string proc-buffer "\n"))) + +(defun lua-ts-show-process-buffer () + "Show the inferior Lua process buffer." + (interactive) + (display-buffer lua-ts-inferior-buffer)) + +(defun lua-ts-hide-process-buffer () + "Hide the inferior Lua process buffer." + (interactive) + (delete-windows-on lua-ts-inferior-buffer)) + +(defun lua-ts-kill-process () + "Kill the inferior Lua process." + (interactive) + (with-current-buffer lua-ts-inferior-buffer + (kill-buffer-and-window))) + +(defun lua-ts-inferior--write-history (process _) + "Write history file for inferior Lua PROCESS." + ;; Depending on how the process is killed the buffer may not be + ;; around anymore; e.g. `kill-buffer'. + (when-let* ((buffer (process-buffer process)) + ((buffer-live-p (process-buffer process)))) + (with-current-buffer buffer (comint-write-input-ring)))) + +(defvar lua-ts-mode-map + (let ((map (make-sparse-keymap "Lua"))) + (define-key map "\C-c\C-n" 'lua-ts-inferior-lua) + (define-key map "\C-c\C-c" 'lua-ts-send-buffer) + (define-key map "\C-c\C-l" 'lua-ts-send-file) + (define-key map "\C-c\C-r" 'lua-ts-send-region) + map) + "Keymap for `lua-ts-mode' buffers.") + +(easy-menu-define lua-ts-mode-menu lua-ts-mode-map + "Menu bar entry for `lua-ts-mode'." + `("Lua" + ["Evaluate Buffer" lua-ts-send-buffer] + ["Evaluate File" lua-ts-send-file] + ["Evaluate Region" lua-ts-send-region] + "--" + ["Start Process" lua-ts-inferior-lua] + ["Show Process Buffer" lua-ts-show-process-buffer] + ["Hide Process Buffer" lua-ts-hide-process-buffer] + ["Kill Process" lua-ts-kill-process] + "--" + ["Customize" (lambda () (interactive) (customize-group "lua-ts"))])) ;;;###autoload (define-derived-mode lua-ts-mode prog-mode "Lua" - "Major mode for editing Lua files, powered by tree-sitter." + "Major mode for editing Lua files, powered by tree-sitter. + +\\{lua-ts-mode-map}" :syntax-table lua-ts--syntax-table + (use-local-map lua-ts-mode-map) (when (treesit-ready-p 'lua) (treesit-parser-create 'lua) @@ -415,7 +639,9 @@ lua-ts-mode "while_statement"))) (sexp ,(rx (or "arguments" "block" + "function_declaration" "parameters" + "parenthesized_expression" "string" "table_constructor"))) (text "comment")))) diff --git a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts index 040225c8580..25d29e0fbc5 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts @@ -5,148 +5,645 @@ Code: (lua-ts-mode) (indent-region (point-min) (point-max))) -Name: Basic Indent +Name: Chunk Indent =-= - print( -0, - 1 -) + print(1) + print(2) +=-= +print(1) +print(2) +=-=-= -local function f(o) - if o.x > o.y then - return o.x -elseif o.y > o.z then - return o.y - else -return o.z - end +Name: Function Indent + +=-= +function f1(n) +print(n) +return n + 1 end -f({ - x = 1, - y = 2, - z = 3, -}) +local function f2(n) +print(n) +return n * 2 +end -;(function() -return false -)() +local f3 = function(n) +print(n) +return n / 3 +end + +function f4(...) +local f = function (...) +if ok +then print(1) +else print(0) +end +end +return f +end + +function f5(...) +local f = function (...) +if ok +then +print(1) +else +print(0) +end +end +return f +end + +function f6(...) +local f = function (...) +if ok then +print(1) +else +print(0) +end +end +return f +end + +;(function () + return true + end)() =-= -print( - 0, - 1 -) +function f1(n) + print(n) + return n + 1 +end + +local function f2(n) + print(n) + return n * 2 +end -local function f(o) - if o.x > o.y then - return o.x - elseif o.y > o.z then - return o.y - else - return o.z +local f3 = function(n) + print(n) + return n / 3 +end + +function f4(...) + local f = function (...) + if ok + then print(1) + else print(0) + end end + return f end -f({ - x = 1, - y = 2, - z = 3, -}) +function f5(...) + local f = function (...) + if ok + then + print(1) + else + print(0) + end + end + return f +end -;(function() - return false -)() +function f6(...) + local f = function (...) + if ok then + print(1) + else + print(0) + end + end + return f +end + +;(function () + return true +end)() =-=-= -Name: Argument Indent +Name: Conditional Indent =-= -function h( -string, -number, -options) -print(string, number, options) +if true then +print(true) +return 1 +elseif false then +print(false) +return -1 +else +print(nil) +return 0 end -local p = h( -"sring", - 1000, - { -cost = 2, -length = 8, - parallelism = 4, -}) +if true + then + print(true) + return 1 + elseif false + then + print(false) + return -1 + else + print(nil) + return 0 +end + +if true + then return 1 + elseif false + then return -1 + else return 0 +end =-= -function h( - string, - number, - options) - print(string, number, options) +if true then + print(true) + return 1 +elseif false then + print(false) + return -1 +else + print(nil) + return 0 end -local p = h( - "sring", - 1000, - { - cost = 2, - length = 8, - parallelism = 4, - }) +if true +then + print(true) + return 1 +elseif false +then + print(false) + return -1 +else + print(nil) + return 0 +end + +if true +then return 1 +elseif false +then return -1 +else return 0 +end +=-=-= + +Name: Loop Indent + +=-= +for k,v in pairs({}) do + print(k) + print(v) +end + +for i=1,10 + do print(i) +end + +while n < 10 do + n = n + 1 + print(n) +end + +while n < 10 + do + n = n + 1 + print(n) +end + +for i=0,9 do +repeat n = n+1 + until n > 99 +end + +repeat +z = z * 2 +print(z) +until z > 12 + + for i,x in ipairs(t) do + while i < 9 + do + local n = t[x] + repeat n = n + 1 + until n > #t + while n < 99 + do + print(n) + end + end + print(t[i]) + end +=-= +for k,v in pairs({}) do + print(k) + print(v) +end + +for i=1,10 +do print(i) +end + +while n < 10 do + n = n + 1 + print(n) +end + +while n < 10 +do + n = n + 1 + print(n) +end + +for i=0,9 do + repeat n = n+1 + until n > 99 +end + +repeat + z = z * 2 + print(z) +until z > 12 + +for i,x in ipairs(t) do + while i < 9 + do + local n = t[x] + repeat n = n + 1 + until n > #t + while n < 99 + do + print(n) + end + end + print(t[i]) +end +=-=-= + +Name: Bracket Indent + +=-= +fn( + ) + +tb={ + } +=-= +fn( +) + +tb={ +} =-=-= -Name: Continuation Indent +Name: Multi-line String Indent =-= +local s = [[ + Multi-line + string content + ]] + function f() local str = [[ multi-line string ]] ---[[ -multi-line -comment - ]] return true end =-= +local s = [[ + Multi-line + string content + ]] + function f() local str = [[ multi-line string ]] - --[[ + return true +end +=-=-= + +Name: Multi-line Comment Indent + +=-= +--[[ + Multi-line + comment content + ]] + +function f() +--[[ +multi-line + comment + ]] + return true +end +=-= +--[[ + Multi-line + comment content + ]] + +function f() +--[[ multi-line -comment + comment ]] return true end =-=-= -Name: Loop Indent +Name: Argument Indent =-= -for k, v in pairs({}) do - print(k, v) + h( + "string", + 1000 + ) + +local p = h( +"string", + 1000 +) + +fn(1, +2, + 3) + +fn( 1, 2, +3, 4 ) + +f({ +x = 1, +y = 2, +z = 3, +}) + +f({ x = 1, +y = 2, +z = 3, }) +=-= +h( + "string", + 1000 +) + +local p = h( + "string", + 1000 +) + +fn(1, + 2, + 3) + +fn( 1, 2, + 3, 4 ) + +f({ + x = 1, + y = 2, + z = 3, +}) + +f({ x = 1, + y = 2, + z = 3, }) +=-=-= + +Name: Parameter Indent + +=-= +function f1( +a, +b +) +print(a,b) end -while n < 10 do -n = n + 1 +local function f2(a, + b) +print(a,b) end -repeat -z = z * 2 - until z > 12 +local f3 = function( a, b, + c, d ) +print(a,b,c,d) +end =-= -for k, v in pairs({}) do - print(k, v) +function f1( + a, + b +) + print(a,b) end -while n < 10 do - n = n + 1 +local function f2(a, + b) + print(a,b) end -repeat - z = z * 2 -until z > 12 +local f3 = function( a, b, + c, d ) + print(a,b,c,d) +end +=-=-= + +Name: Table Indent + +=-= +local Other = { + First={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Second={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Third={up={Goto=true}, + down={Goto=true}, + left={Goto=true}, + right={Goto=true}} +} + +local Other = { +a = 1, + b = 2, + c = 3, +} +=-= +local Other = { + First={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Second={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Third={up={Goto=true}, + down={Goto=true}, + left={Goto=true}, + right={Goto=true}} +} + +local Other = { + a = 1, + b = 2, + c = 3, +} +=-=-= + +Code: + (lambda () + (setq indent-tabs-mode nil) + (setq lua-ts-indent-offset 4) + (lua-ts-mode) + (indent-region (point-min) (point-max))) + +Name: End Indent + +=-= +function f(x) + for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end end end end + return {x,y} or {math.random(),math.random()} + end + +for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end + end end end +=-= +function f(x) + for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end end end end + return {x,y} or {math.random(),math.random()} +end + +for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end +end end end +=-=-= + +Name: Nested Function Indent + +=-= +function a(...) + return (function (x) + return x + end)(foo(...)) +end + +function b(n) + local x = 1 + return function (i) + return function (...) + return (function (n, ...) + return function (f, ...) + return (function (...) + if ... and x < 9 then + x = x + 1 + return ... + end end)(n(f, ...)) + end, ... + end)(i(...)) +end end end + +function c(f) + local f1 = function (...) + if nil ~= ... then + return f(...) + end + end + return function (i) + return function (...) + local fn = function (n, ...) + local x = function (f, ...) + return f1(n(f, ...)) + end + return x + end + return fn(i(...)) + end + end +end + +function d(f) + local f1 = function (c, f, ...) + if ... then + if f(...) then + return ... + else + return c(f, ...) + end end end + return function (i) + return function (...) + return (function (n, ...) + local function j (f, ...) + return f1(j, f, n(f, ...)) + end + return j, ... + end)(i(...)) +end end end + +function e (n, t) + return function (i) + return function (...) + return ( + function (n, ...) + local x, y, z = 0, {} + return (function (f, ...) + return (function (i, ...) return i(i, ...) end)( + function (i, ...) + return f(function (x, ...) + return i(i, ...)(x, ...) + end, ...) + end) + end)(function (j) + return function(f, ...) + return (function (c, f, ...) + if ... then + if n+1 == x then + local y1, x1 = y, x + y, x = {}, 0 + return (function (...) + z = ... + return ... + end)(t(y1-1, x1-1, ...)) + else + x = x - 1 + return c(f, + (function (...) + z = ... + return ... + end)(t(y, x, ...))) + end + elseif x ~= 0 then + x = 0 + return z, y + end end)(j, f, n(f, ...)) + end end), ... + end)(i(...)) +end end end =-=-= diff --git a/test/lisp/progmodes/lua-ts-mode-resources/movement.erts b/test/lisp/progmodes/lua-ts-mode-resources/movement.erts index 770aa23b18d..afebe93de3f 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/movement.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/movement.erts @@ -481,6 +481,34 @@ local t = { 1, 3 }| =-=-= +Name: forward-sexp moves over parenthesized expressions + +=-= +|(function (x) return x + 1 end)(41) +=-= +(function (x) return x + 1 end)|(41) +=-=-= + +Name: forward-sexp moves over function declarations + +=-= +|function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end +=-= +function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end| +=-=-= + Code: (lambda () (lua-ts-mode) @@ -551,3 +579,31 @@ local t = |{ 1, 2, 3 } =-=-= + +Name: backward-sexp moves over parenthesized expressions + +=-= +(function (x) return x + 1 end)|(41) +=-= +|(function (x) return x + 1 end)(41) +=-=-= + +Name: backward-sexp moves over function declarations + +=-= +function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end| +=-= +|function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end +=-=-= -- 2.41.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 07 06:12:17 2023 Received: (at 66159) by debbugs.gnu.org; 7 Oct 2023 10:12:17 +0000 Received: from localhost ([127.0.0.1]:53355 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qp4IA-0008Vj-MR for submit@debbugs.gnu.org; Sat, 07 Oct 2023 06:12:17 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:51238) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qp4I8-0008VT-G9 for 66159@debbugs.gnu.org; Sat, 07 Oct 2023 06:12:13 -0400 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-27734d76e1bso2107437a91.2 for <66159@debbugs.gnu.org>; Sat, 07 Oct 2023 03:11:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696673507; x=1697278307; darn=debbugs.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=aIoqxzqwOmu4sO5PujH5ds0lRYsOeJhlNJbxCY+xr8k=; b=I7HvnRebyvi9vv3ucCDvB5IOglqFDamTIyFSPlfEFdca3XSOthPzrtmxfXc0OJz9gj 3457Xbdz+62M2glrfYqxb1W3zbpW5i9UaDJr2FpbghESc8iuxADjLJctDsOQMFjZxXn8 lyc7gh1ZOtw1lC5nQ6Nedt33SdE7AVXXxlFZ/p0qR4Zy/IO4Jk68gFITyTgUImUpU8b+ aP60yU2hta/8Z6WtYFv95IzJSQGk3mgLt7btrTDtFmdHlnvNNMfkGaSe25VseiTloEpp V4SurIAANyrDtjClZocDdnJrFvzXP6+QrHBQ5MLSvXObkDuUJYoViDBBbU1h4F5fmK+1 dNGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696673507; x=1697278307; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aIoqxzqwOmu4sO5PujH5ds0lRYsOeJhlNJbxCY+xr8k=; b=QIGE1ncUk4FakFclmM0tvOs0uHofB6HCUveW32AeDkkutCesmlZf0o4JOY5bzcDplj y0SJiJxplsiwkHsaMmPpRGC669JmhiBx6BBOJpTSM6i3Z0CPuSTEDCu6v2d5p7WnDtls Eop/V/I2NMFtmxKuJ89gWfIyP9Wv70Md6I/TByzrtyY6qIm7NTzOHzX1Y9omWXOROo3M KIoan6sTmaWIvx1J9Qwt/D/bmZ09xfOwvVC1DPFj61dNlKvl+9G2C97MiZCS8N++VGcj noCu7QGkh5Clz4aT1pUpKLXojqHsxqxbsmDdzULzJDdMJi1S9qOdOWzlWOb4P+y7xikI 3EsA== X-Gm-Message-State: AOJu0YxOCm0Lz7dYq7AmKpSJAIkVP6UixgKUOEkvmkM6cWL/1oLqUNOm Uk8vwtUEOT77dj9PVe5lZv8= X-Google-Smtp-Source: AGHT+IFwAMFTl2vPb1ApGILeevAq1tqvJv+2yd2kwXIukYUd/TG8va20i5hbYwj/b9pFG+bLnrLrcw== X-Received: by 2002:a17:90b:4b4b:b0:276:79b6:8bd6 with SMTP id mi11-20020a17090b4b4b00b0027679b68bd6mr9691685pjb.15.1696673507073; Sat, 07 Oct 2023 03:11:47 -0700 (PDT) Received: from [192.168.0.234] ([152.168.142.156]) by smtp.gmail.com with ESMTPSA id bb16-20020a17090b009000b00274bbfc34c8sm6866236pjb.16.2023.10.07.03.11.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 Oct 2023 03:11:46 -0700 (PDT) Message-ID: Date: Sat, 7 Oct 2023 07:11:42 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#66159: [PATCH] Various improvements to lua-ts-mode (Bug#66159) Content-Language: en-US To: john muhl , 66159@debbugs.gnu.org References: <87fs36vvxl.fsf@gmail.com> <8734ynz15f.fsf@pub.pink> From: Mauro Aranda In-Reply-To: <8734ynz15f.fsf@pub.pink> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159 Cc: Andrey Listopadov X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 6/10/23 16:44, john muhl via Bug reports for GNU Emacs, the Swiss army knife of text editors wrote: > +(defcustom lua-ts-inferior-history nil > + "File used to save command history of the inferior Lua process." > + :type '(choice (const nil) file) Please, give a :tag for the const option. IMO, it makes for a better Customize UI. From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 07 12:16:48 2023 Received: (at 66159) by debbugs.gnu.org; 7 Oct 2023 16:16:48 +0000 Received: from localhost ([127.0.0.1]:55770 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qp9yx-0005cw-U9 for submit@debbugs.gnu.org; Sat, 07 Oct 2023 12:16:48 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]:45478) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qp9yv-0005ci-Uy for 66159@debbugs.gnu.org; Sat, 07 Oct 2023 12:16:46 -0400 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-99bf3f59905so554058066b.3 for <66159@debbugs.gnu.org>; Sat, 07 Oct 2023 09:16:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696695380; x=1697300180; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:from:to:cc:subject:date :message-id:reply-to; bh=9lg2yvE8+oznsrUECsYCxFEPDD0s8QBbnJtHUuj+AQg=; b=ZmBOwGCyiP4BJcoWd2OBqcL2ucBvO402VgP4dH2BGg5TwxWdQtglZlIwLe4eatHgJj 3SI7AP/j2mpmkR6urnuVDwMrgxrz/UPhmex6G6zpwmVcijtXEq9L8CJrD8LSV5bNr6J9 qCnnavtNugmZl9KX83j9zVH/G7Fc0bIU2p20BWgqVZK7/Qf1EraH4PzKDCgD5f3SNH+p nqkLLgdxeouLkz72WkdUwrAuESvan47yerIHafChfy5u6QwbE7R4mCdnWAlmJLf2KbKw WItlF7w/cc1d3sHuHwvrBxZsgUsp2792LB9pa7MJTfeI3jPpz3xKRW9XWRiHPd+HcWW7 YkmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696695380; x=1697300180; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=9lg2yvE8+oznsrUECsYCxFEPDD0s8QBbnJtHUuj+AQg=; b=VSXDBRVzUYGuGEMWHomF0qrLS3vDmImyIDkCtyNkVY45q4hvKVh5YLhQFGskXEfB64 y1Ff14zdX4GbU9vcVvykrqjKk4pCxyFYq6bLOFWCo4X8ek9XvGwkbWWZDj+auMIZFpiM l2F83eTCjOc3E9oAivRpTG7A5i8FvO8YtcG/YEAoZWdJNUm9Ci4NbJqaLIkJgUybYRXI 9q9bcwzU/lC8761ONMdJVfV6SXZrwtd/HRAkKt/8zS8wGdAXj/3VBrwC81Puf8L2j41p jR1snwaBNB2FjquQwJluy1CtaLjXiDd4cLyUZBrYmhUqdfQNn/oNIv0cxULcSsiwvj+I G6OA== X-Gm-Message-State: AOJu0YzGFs2TVguUkr7HtzT/9vCHVb+cn+8Z6WoyWUfuTW4RwJMSo9Xr oPo9m4hVIloLdR8iawfWddN+dC7I7Cs= X-Google-Smtp-Source: AGHT+IHuvRrAqyPu/Ip7qytQkaOkrFqeYUomVwVyE5Zc5TvOocQ8rXnhMS94y0th6VuF2wh31UlznQ== X-Received: by 2002:a17:907:78c7:b0:9ae:7548:742 with SMTP id kv7-20020a17090778c700b009ae75480742mr9595297ejc.3.1696695380211; Sat, 07 Oct 2023 09:16:20 -0700 (PDT) Received: from toolbox.smtp.gmail.com (broadband-90-154-71-4.ip.moscow.rt.ru. [90.154.71.4]) by smtp.gmail.com with ESMTPSA id dc4-20020a170906c7c400b0098e34446464sm4453259ejb.25.2023.10.07.09.16.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 09:16:19 -0700 (PDT) References: <8734ynz15f.fsf@pub.pink> User-agent: mu4e 1.8.11; emacs 30.0.50 From: Andrey Listopadov To: john muhl Subject: Re: [PATCH] Various improvements to lua-ts-mode (Bug#66159) Date: Sat, 07 Oct 2023 19:15:44 +0300 In-reply-to: <8734ynz15f.fsf@pub.pink> Message-ID: <87zg0u9zn2.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159 Cc: 66159@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) john muhl writes: > Tags: patch > > Here is a cleaned up patch. A couple of small additions unrelated to > this bug are included but I can separate them if anyone prefers. The > additions are: > > - Make lua-ts-mode-hook a defcustom. > - Add an option to use a history file for inferior process input. > > Andrey if you could test this one it=E2=80=99d be appreciated. Thanks for= your > help. > > [2. text/x-patch; 0001-Various-improvements-to-lua-ts-mode-Bug-66159.patc= h]... It seems the last patch broke the movement. -- Andrey Listopadov From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 07 14:13:44 2023 Received: (at 66159) by debbugs.gnu.org; 7 Oct 2023 18:13:44 +0000 Received: from localhost ([127.0.0.1]:55870 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qpBo8-0001BN-HW for submit@debbugs.gnu.org; Sat, 07 Oct 2023 14:13:44 -0400 Received: from out-205.mta0.migadu.com ([2001:41d0:1004:224b::cd]:58859) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qpBo5-0001BE-Vt for 66159@debbugs.gnu.org; Sat, 07 Oct 2023 14:13:42 -0400 References: <8734ynz15f.fsf@pub.pink> <87zg0u9zn2.fsf@gmail.com> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1696702400; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NeTAsJ4re31H1WWSymlhyEktSiTuhSNXDV3c8Fbhlrw=; b=dV8JEQicvhQGQ/sCASkkeDUnuuWkaNqOw5tyd1UdQ9G/V6gtvOPAGUF17Z166tmWrxkQcH /VxISv9PQmiEr1UigsXnGlCfKFNuwypXvjFX/0sl+a42zgNk1+jIPhXZYLtKe/IHdmbLKd +VbLtWNPU/0rsEIpRvTs+9G0dm5pArM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: john muhl To: Andrey Listopadov Subject: Re: [PATCH] Various improvements to lua-ts-mode (Bug#66159) Date: Sat, 07 Oct 2023 13:10:31 -0500 In-reply-to: <87zg0u9zn2.fsf@gmail.com> Message-ID: <87edi6xpvn.fsf@pub.pink> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159 Cc: 66159@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Andrey Listopadov writes: > john muhl writes: > >> Tags: patch >> >> Here is a cleaned up patch. A couple of small additions unrelated to >> this bug are included but I can separate them if anyone prefers. The >> additions are: >> >> - Make lua-ts-mode-hook a defcustom. >> - Add an option to use a history file for inferior process input. >> >> Andrey if you could test this one it=E2=80=99d be appreciated. Thanks fo= r your >> help. >> >> [2. text/x-patch; 0001-Various-improvements-to-lua-ts-mode-Bug-66159.pat= ch]... > > It seems the last patch broke the movement. The tests for those pass and are still working here. Maybe you found another case that needs to be improved. What is the specific problem? From debbugs-submit-bounces@debbugs.gnu.org Sun Oct 08 05:54:08 2023 Received: (at 66159) by debbugs.gnu.org; 8 Oct 2023 09:54:08 +0000 Received: from localhost ([127.0.0.1]:56263 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qpQUB-0007WK-O7 for submit@debbugs.gnu.org; Sun, 08 Oct 2023 05:54:08 -0400 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]:51687) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qpQU8-0007Vo-Cp for 66159@debbugs.gnu.org; Sun, 08 Oct 2023 05:54:05 -0400 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5344d996bedso6335447a12.3 for <66159@debbugs.gnu.org>; Sun, 08 Oct 2023 02:53:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696758818; x=1697363618; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:from:to:cc:subject:date :message-id:reply-to; bh=syYq0qlGvBQbVTPK9E8yTLxVnm6oEvJOn8aTrvHTTAY=; b=Qm4LsDqR+IMwMQQ3VrOh9+UH9HCci2unUdhjpCu1VSscMhC/2R8PheIDm7v6ZvbB9o BGzZRt8ZhJUUxKKAJG4hUwghKbIEHFWhOFJLBJIEMhCFqJB2ydYBDneaKqYig6vXna0j foZEbRuFVvPjN+exAtWwiZXcxdlIF803275uF+fKqrRRhYVseIN3D3SsDsus/dTN+VQ/ hbrwdFafp4H9srpcoehiwaYweU0FHXPZj01fGnoZunVO13r3/jgG8VWdLKizf5TT9BKk IFARtJgbvHdlLX8KmW7r1LVyrh0fRUAwy9JVAL7qTh+mZd17TdT4jVulndeTcvTUy70P 0mHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696758818; x=1697363618; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=syYq0qlGvBQbVTPK9E8yTLxVnm6oEvJOn8aTrvHTTAY=; b=wKxom3iw/9V1QlxQt8fXKHB18+avIehuas6GYYXXReCUa4oBK2gEsuDwl1OBSl3hWu dBqbfnYbB4ABJ9U4CTdtzgta+hxusfoqf91b5DGZX5LwJsegYDYWN35fuiZTZuvcHgjd bmG7JybMaJdiIuRE8Sq23uw7AzHBPVyR2nJGCpBfC6M9rmrxKTbxDpfbMkWktRJmWYPn bU+UWZTZIAuTGAWZcgqxaDFYaZl9BJFVNzu8tkieurtbJa0soolIXnpQeqh2Bjzn7TyO Sw9S7sNO5vPZsjy/eWA6NcCTcePJQYl2GFKRPRvOD7Lkh8TaXwamk72XFnOqeo97pktR +ElA== X-Gm-Message-State: AOJu0YwDm4g+VBc7lpiuDRo6kBCSgggZdolTgUTbgVt1RJhmBLRsIvnt tJLihgzp8WQ5FUuQCb2faV1ibZU4cks= X-Google-Smtp-Source: AGHT+IH3lDAjtGVGJAdhasnVUMCTFvYFNnjGOJSig5chqrzFn4XHLwX+w+TAyZqdlreCnP1zfssQSw== X-Received: by 2002:a17:906:32cc:b0:9ae:65d6:b882 with SMTP id k12-20020a17090632cc00b009ae65d6b882mr12485255ejk.40.1696758818317; Sun, 08 Oct 2023 02:53:38 -0700 (PDT) Received: from toolbox.smtp.gmail.com (broadband-90-154-71-4.ip.moscow.rt.ru. [90.154.71.4]) by smtp.gmail.com with ESMTPSA id si5-20020a170906cec500b009b97d9ae329sm5339478ejb.198.2023.10.08.02.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 02:53:37 -0700 (PDT) References: <8734ynz15f.fsf@pub.pink> <87zg0u9zn2.fsf@gmail.com> <87edi6xpvn.fsf@pub.pink> User-agent: mu4e 1.8.11; emacs 30.0.50 From: Andrey Listopadov To: john muhl Subject: Re: [PATCH] Various improvements to lua-ts-mode (Bug#66159) Date: Sun, 08 Oct 2023 12:43:50 +0300 In-reply-to: <87edi6xpvn.fsf@pub.pink> Message-ID: <87r0m5qw2n.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159 Cc: 66159@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) john muhl writes: >> It seems the last patch broke the movement. > > The tests for those pass and are still working here. Maybe you found > another case that needs to be improved. What is the specific problem? It seems so, sorry for not including this, I thought I sent this before. Here's an example: =E2=96=88for i=3D1,10 do print(x) end Pressing Pressing C-M-f (forward-sexp) puts the point here: for i=3D1,10 do print(x)=E2=96=88 end I think it should go over the `for' loop right to the `end'. Pressing Pressing C-M-b (backward-sexp), however, puts the point here: for i=3D1,10 do =E2=96=88print(x) end Pressing C-M-b again doesn't move the point anymore. Same thing happens with for-each style loop: =E2=96=88for k,v in pairs({1,2,3}) do print(x) end C-M-f: for k,v in pairs({1,2,3})=E2=96=88do print(x) end C-M-f: for k,v in pairs({1,2,3}) do print(x)=E2=96=88 end Backward movement manages to take the point way back to the pairs: C-M-b, C-M-b: for k,v in pairs=E2=96=88({1,2,3}) do print(x) end I went to https://devhints.io/lua and copied a bunch of examples of other loops to the scratch buffer, and the movement is as follows: =E2=96=88while condition do end for i =3D 1,5 do end for i =3D start,finish,delta do end for k,v in pairs(tab) do end repeat until condition -- Breaking out: while x do if condition then break end end C-M-f: while condition do end for i =3D 1,5 do end for i =3D start,finish,delta do end for k,v in pairs(tab)=E2=96=88do end repeat until condition -- Breaking out: while x do if condition then break end end C-M-f: while condition do end for i =3D 1,5 do end for i =3D start,finish,delta do end for k,v in pairs(tab) do end repeat until condition -- Breaking out: while x do if condition then break end=E2=96=88 end -- Andrey Listopadov From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 09 03:10:47 2023 Received: (at 66159) by debbugs.gnu.org; 9 Oct 2023 07:10:47 +0000 Received: from localhost ([127.0.0.1]:59087 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qpkPd-00027V-J0 for submit@debbugs.gnu.org; Mon, 09 Oct 2023 03:10:47 -0400 Received: from out-200.mta0.migadu.com ([2001:41d0:1004:224b::c8]:64873) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qpkPY-00027J-OX for 66159@debbugs.gnu.org; Mon, 09 Oct 2023 03:10:43 -0400 References: <8734ynz15f.fsf@pub.pink> <87zg0u9zn2.fsf@gmail.com> <87edi6xpvn.fsf@pub.pink> <87r0m5qw2n.fsf@gmail.com> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1696835418; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LRQL5RCfko2mRpkzQiFzpEXqx1D5+BpYMoMNp4ZoWAI=; b=pFPW8gDAP0bElb9GEINPK/jmHhMUytBjnffIqZ0wkIxIxDmzox3ixjZR8fOMZ/T6VwwWiJ g5KJBYuPwMk2v+OAQl+7NWX2Oln2bfcudgb8WwonRSrbr5csIL395p9OWbCCcYteFuGoid D/9Scp1z0woCnuQI9v/4DueNbAQU0tQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: john muhl To: 66159@debbugs.gnu.org Subject: Re: [PATCH] Various improvements to lua-ts-mode (Bug#66159) Date: Sun, 08 Oct 2023 22:28:02 -0500 In-reply-to: <87r0m5qw2n.fsf@gmail.com> Message-ID: <87edi4mfu1.fsf@pub.pink> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Flow: FLOW_OUT X-Spam-Score: 1.1 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Mauro Aranda writes: > On 6/10/23 16:44, john muhl via Bug reports for GNU Emacs, the Swiss > army knife of text editors wrote: > >> +(defcustom lua-ts-inferior-history nil >> + "File used to save command history of the i [...] Content analysis details: (1.1 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 1.1 DATE_IN_PAST_03_06 Date: is 3 to 6 hours before Received: date -0.0 SPF_PASS SPF: sender matches SPF record X-Debbugs-Envelope-To: 66159 Cc: Andrey Listopadov , Mauro Aranda X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.1 (/) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mauro Aranda writes: > On 6/10/23 16:44, john muhl via Bug reports for GNU Emacs, the Swiss > army knife of text editors wrote: > >> +(defcustom lua-ts-inferior-history nil >> + "File used to save command history of the inferior Lua process." >> + :type '(choice (const nil) file) > > Please, give a :tag for the const option. IMO, it makes for a better > Customize UI. Fixed here and for the other choices. Andrey Listopadov writes: > john muhl writes: > >>> It seems the last patch broke the movement. >> >> The tests for those pass and are still working here. Maybe you found >> another case that needs to be improved. What is the specific problem? > > It seems so, sorry for not including this, I thought I sent this before. > Here's an example: > > > =E2=96=88for i=3D1,10 do > print(x) > end > > Pressing Pressing C-M-f (forward-sexp) puts the point here: > > for i=3D1,10 do > print(x)=E2=96=88 > end > > I think it should go over the `for' loop right to the `end'. > > Pressing Pressing C-M-b (backward-sexp), however, puts the point here: > > for i=3D1,10 do > =E2=96=88print(x) > end > > Pressing C-M-b again doesn't move the point anymore. > > Same thing happens with for-each style loop: > > =E2=96=88for k,v in pairs({1,2,3}) do > print(x) > end > > C-M-f: > > for k,v in pairs({1,2,3})=E2=96=88do > print(x) > end > > C-M-f: > > for k,v in pairs({1,2,3}) do > print(x)=E2=96=88 > end > > Backward movement manages to take the point way back to the pairs: > > C-M-b, C-M-b: > > for k,v in pairs=E2=96=88({1,2,3}) do > print(x) > end > > I went to https://devhints.io/lua and copied a bunch of examples of > other loops to the scratch buffer, and the movement is as follows: > > =E2=96=88while condition do > end > > for i =3D 1,5 do > end > > for i =3D start,finish,delta do > end > > for k,v in pairs(tab) do > end > > repeat > until condition > > -- Breaking out: > while x do > if condition then break end > end > > C-M-f: > > while condition do > end > > for i =3D 1,5 do > end > > for i =3D start,finish,delta do > end > > for k,v in pairs(tab)=E2=96=88do > end > > repeat > until condition > > -- Breaking out: > while x do > if condition then break end > end > > C-M-f: > > while condition do > end > > for i =3D 1,5 do > end > > for i =3D start,finish,delta do > end > > for k,v in pairs(tab) do > end > > repeat > until condition > > -- Breaking out: > while x do > if condition then break end=E2=96=88 > end Navigation should be all around improved now. Let me know if I missed somet= hing. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Various-improvements-to-lua-ts-mode-Bug-66159.patch >From de03aed39d67f0a14b2586e59b2b713891bc37d0 Mon Sep 17 00:00:00 2001 From: john muhl Date: Wed, 4 Oct 2023 20:46:15 -0500 Subject: [PATCH] Various improvements to lua-ts-mode (Bug#66159) * lisp/progmodes/lua-ts-mode.el (lua-ts-mode): Navigate function declarations and parenthesized expressions with *-sexp commands. (lua-ts--simple-indent-rules): Improve indentation rules. (lua-ts-mode-map): Add key bindings and menus. (lua-ts-mode-hook): Make hook available in Customize. (lua-ts-inferior-history): (lua-ts-inferior--write-history): Add option to read/write an input history file. (lua-ts-inferior-lua): (lua-ts-send-buffer): (lua-ts-send-file): (lua-ts-send-region): (lua-ts-inferior-prompt): (lua-ts-inferior-prompt-continue): Support for sending buffer, file or region to the inferior process. (lua-ts-show-process-buffer): (lua-ts-hide-process-buffer): (lua-ts-kill-process): New functions. (lua-ts-inferior-prompt-regexp): Remove option. * test/lisp/progmodes/lua-ts-mode-resources/indent.erts: * test/lisp/progmodes/lua-ts-mode-resources/movement.erts: Add tests. --- lisp/progmodes/lua-ts-mode.el | 369 +++++++-- .../lua-ts-mode-resources/indent.erts | 705 +++++++++++++++--- .../lua-ts-mode-resources/movement.erts | 156 ++-- 3 files changed, 1032 insertions(+), 198 deletions(-) diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index 030a3585158..e7a36f3bb93 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -38,7 +38,11 @@ (require 'cl-lib) (require 'rx)) +(declare-function treesit-induce-sparse-tree "treesit.c") (declare-function treesit-node-child-by-field-name "treesit.c") +(declare-function treesit-node-first-child-for-pos "treesit.c") +(declare-function treesit-node-parent "treesit.c") +(declare-function treesit-node-start "treesit.c") (declare-function treesit-node-type "treesit.c") (declare-function treesit-parser-create "treesit.c") (declare-function treesit-search-subtree "treesit.c") @@ -48,6 +52,15 @@ lua-ts :prefix "lua-ts-" :group 'languages) +(defcustom lua-ts-mode-hook nil + "Hook run after entering `lua-ts-mode'." + :type 'hook + :options '(flymake-mode + hs-minor-mode + outline-minor-mode) + :group 'lua-ts + :version "30.1") + (defcustom lua-ts-indent-offset 4 "Number of spaces for each indentation step in `lua-ts-mode'." :type 'natnum @@ -57,7 +70,7 @@ lua-ts-indent-offset (defcustom lua-ts-luacheck-program "luacheck" "Location of the Luacheck program." - :type '(choice (const nil) string) + :type '(choice (const :tag "None" nil) string) :group 'lua-ts :version "30.1") @@ -70,7 +83,7 @@ lua-ts-inferior-buffer (defcustom lua-ts-inferior-program "lua" "Program to run in the inferior Lua process." - :type '(choice (const nil) string) + :type '(choice (const :tag "None" nil) string) :group 'lua-ts :version "30.1") @@ -82,13 +95,28 @@ lua-ts-inferior-options (defcustom lua-ts-inferior-startfile nil "File to load into the inferior Lua process at startup." - :type '(choice (const nil) (file :must-match t)) + :type '(choice (const :tag "None" nil) (file :must-match t)) + :group 'lua-ts + :version "30.1") + +(defcustom lua-ts-inferior-prompt ">" + "Prompt used by the inferior Lua process." + :type 'string + :safe 'stringp + :group 'lua-ts + :version "30.1") + +(defcustom lua-ts-inferior-prompt-continue ">>" + "Continuation prompt used by the inferior Lua process." + :type 'string + :safe 'stringp :group 'lua-ts :version "30.1") -(defcustom lua-ts-inferior-prompt-regexp "^>>?[[:blank:]]" - "Regular expression matching the prompt of the inferior Lua process." - :type 'regexp +(defcustom lua-ts-inferior-history nil + "File used to save command history of the inferior Lua process." + :type '(choice (const :tag "None" nil) file) + :safe 'string-or-null-p :group 'lua-ts :version "30.1") @@ -103,6 +131,12 @@ lua-ts--builtins "close" "flush" "lines" "read" "seek" "setvbuf" "write") "Lua built-in functions for tree-sitter font-locking.") +(defvar lua-ts--keywords + '("and" "do" "else" "elseif" "end" "for" "function" + "goto" "if" "in" "local" "not" "or" "repeat" + "return" "then" "until" "while") + "Lua keywords for tree-sitter font-locking and navigation.") + (defvar lua-ts--font-lock-settings (treesit-font-lock-rules :language 'lua @@ -167,13 +201,11 @@ lua-ts--font-lock-settings :language 'lua :feature 'keyword - '((break_statement) @font-lock-keyword-face + `((break_statement) @font-lock-keyword-face (true) @font-lock-constant-face (false) @font-lock-constant-face (nil) @font-lock-constant-face - ["and" "do" "else" "elseif" "end" "for" "function" - "goto" "if" "in" "local" "not" "or" "repeat" - "return" "then" "until" "while"] + ,(vconcat lua-ts--keywords) @font-lock-keyword-face) :language 'lua @@ -235,27 +267,135 @@ lua-ts--font-lock-settings (defvar lua-ts--simple-indent-rules `((lua + ((or (node-is "comment") + (parent-is "comment_content") + (parent-is "string_content") + (node-is "]]")) + no-indent 0) + ((and (n-p-gp "field" "table_constructor" "arguments") + lua-ts--multi-arg-function-call-matcher) + parent lua-ts-indent-offset) + ((and (n-p-gp "}" "table_constructor" "arguments") + lua-ts--multi-arg-function-call-matcher) + parent 0) + ((or (node-is "do") + (node-is "then") + (node-is "elseif_statement") + (node-is "else_statement") + (node-is "until") + (node-is ")") + (node-is "}")) + standalone-parent 0) + ((or (and (parent-is "arguments") lua-ts--first-child-matcher) + (and (parent-is "parameters") lua-ts--first-child-matcher) + (and (parent-is "table_constructor") lua-ts--first-child-matcher)) + standalone-parent lua-ts-indent-offset) + ((or (parent-is "arguments") + (parent-is "parameters") + (parent-is "table_constructor")) + (nth-sibling 1) 0) + ((and (n-p-gp "block" "function_definition" "parenthesized_expression") + lua-ts--nested-function-block-matcher + lua-ts--nested-function-block-include-matcher) + parent lua-ts-indent-offset) + ((and (n-p-gp "block" "function_definition" "arguments") + lua-ts--nested-function-argument-matcher) + parent lua-ts-indent-offset) + ((match "function_definition" "parenthesized_expression") + standalone-parent lua-ts-indent-offset) + ((node-is "block") standalone-parent lua-ts-indent-offset) + ((parent-is "block") parent 0) + ((and (node-is "end") lua-ts--end-line-matcher) + standalone-parent lua-ts--end-indent-offset) + ((match "end" "function_declaration") parent 0) + ((and (n-p-gp "end" "function_definition" "parenthesized_expression") + lua-ts--nested-function-end-argument-matcher) + parent 0) + ((and (n-p-gp "end" "function_definition" "parenthesized_expression") + lua-ts--nested-function-block-matcher + lua-ts--nested-function-end-matcher + lua-ts--nested-function-last-function-matcher) + parent 0) + ((n-p-gp "end" "function_definition" "arguments") parent 0) + ((or (match "end" "function_definition") + (node-is "end")) + standalone-parent 0) ((parent-is "chunk") column-0 0) - ((node-is "comment_end") column-0 0) - ((parent-is "block") parent-bol 0) - ((node-is "}") parent-bol 0) - ((node-is ")") parent-bol 0) - ((node-is "else_statement") parent-bol 0) - ((node-is "elseif_statement") parent-bol 0) - ((node-is "end") parent-bol 0) - ((node-is "until") parent-bol 0) - ((parent-is "for_statement") parent-bol lua-ts-indent-offset) - ((parent-is "function_declaration") parent-bol lua-ts-indent-offset) - ((parent-is "function_definition") parent-bol lua-ts-indent-offset) - ((parent-is "if_statement") parent-bol lua-ts-indent-offset) - ((parent-is "else_statement") parent-bol lua-ts-indent-offset) - ((parent-is "repeat_statement") parent-bol lua-ts-indent-offset) - ((parent-is "while_statement") parent-bol lua-ts-indent-offset) - ((parent-is "table_constructor") parent-bol lua-ts-indent-offset) - ((parent-is "arguments") parent-bol lua-ts-indent-offset) - ((parent-is "parameters") parent-bol lua-ts-indent-offset) ((parent-is "ERROR") no-indent 0)))) +(defun lua-ts--end-line-matcher (&rest _) + "Matches if there is more than one `end' on the current line." + (> (lua-ts--end-count) 1)) + +(defun lua-ts--end-indent-offset (&rest _) + "Calculate indent offset based on `end' count." + (- (* (1- (lua-ts--end-count)) lua-ts-indent-offset))) + +(defun lua-ts--end-count () + "Count the number of `end's on the current line." + (count-matches "end" (line-beginning-position) (line-end-position))) + +(defun lua-ts--first-child-matcher (node &rest _) + "Matches if NODE is the first among its siblings." + (= (treesit-node-index node) 1)) + +(defun lua-ts--function-definition-p (node) + "Return t if NODE is a function_definition." + (equal "function_definition" (treesit-node-type node))) + +(defun lua-ts--g-g-g-parent (node) + "Return the great-great-grand-parent of NODE." + (let* ((parent (treesit-node-parent node)) + (g-parent (treesit-node-parent parent)) + (g-g-parent (treesit-node-parent g-parent))) + (treesit-node-parent g-g-parent))) + +(defun lua-ts--multi-arg-function-call-matcher (_n parent &rest _) + "Matches if PARENT has multiple arguments." + (> (treesit-node-child-count (treesit-node-parent parent)) 3)) + +(defun lua-ts--nested-function-argument-matcher (node &rest _) + "Matches if NODE is in a nested function argument." + (save-excursion + (goto-char (treesit-node-start node)) + (treesit-beginning-of-defun) + (backward-char 2) + (not (looking-at ")(")))) + +(defun lua-ts--nested-function-block-matcher (node &rest _) + "Matches if NODE is in a nested function block." + (let* ((g-g-g-parent (lua-ts--g-g-g-parent node)) + (g-g-g-type (treesit-node-type g-g-g-parent))) + (not (equal g-g-g-type "chunk")))) + +(defun lua-ts--nested-function-block-include-matcher (node _p bol &rest _) + "Matches if NODE's child at BOL is not another block." + (let* ((child (treesit-node-first-child-for-pos node bol)) + (child-type (treesit-node-type child)) + (g-g-g-type (treesit-node-type (lua-ts--g-g-g-parent node)))) + (or (equal child-type "assignment_statement") + (and (equal child-type "return_statement") + (or (equal g-g-g-type "arguments") + (and (equal g-g-g-type "expression_list") + (not (treesit-search-subtree child "function_call")))))))) + +(defun lua-ts--nested-function-end-matcher (node &rest _) + "Matches if NODE is the `end' of a nested function." + (save-excursion + (goto-char (treesit-node-start node)) + (treesit-beginning-of-defun) + (looking-at "function[[:space:]]*"))) + +(defun lua-ts--nested-function-end-argument-matcher (node &rest _) + "Matches if great-great-grandparent of NODE is arguments." + (equal "arguments" (treesit-node-type (lua-ts--g-g-g-parent node)))) + +(defun lua-ts--nested-function-last-function-matcher (_n parent &rest _) + "Matches if PARENT is the last nested function." + (let ((sparse-tree + (treesit-induce-sparse-tree parent #'lua-ts--function-definition-p))) + (= 1 (length (cadr sparse-tree))))) + (defvar lua-ts--syntax-table (let ((table (make-syntax-table))) (modify-syntax-entry ?+ "." table) @@ -352,26 +492,124 @@ lua-ts-flymake-luacheck (defun lua-ts-inferior-lua () "Run a Lua interpreter in an inferior process." (interactive) - (let* ((buffer lua-ts-inferior-buffer) - (name (string-replace "*" "" buffer)) - (program lua-ts-inferior-program) - (prompt-regexp lua-ts-inferior-prompt-regexp) - (switches lua-ts-inferior-options) - (startfile lua-ts-inferior-startfile)) - (unless (comint-check-proc buffer) - (set-buffer (apply (function make-comint) name program startfile switches)) + (unless (comint-check-proc lua-ts-inferior-buffer) + (apply #'make-comint-in-buffer + (string-replace "*" "" lua-ts-inferior-buffer) + lua-ts-inferior-buffer + lua-ts-inferior-program + lua-ts-inferior-startfile + lua-ts-inferior-options) + (when lua-ts-inferior-history + (set-process-sentinel (get-buffer-process lua-ts-inferior-buffer) + 'lua-ts-inferior--write-history)) + (with-current-buffer lua-ts-inferior-buffer (setq-local comint-input-ignoredups t + comint-input-ring-file-name lua-ts-inferior-history + comint-use-prompt-regexp t comint-prompt-read-only t - comint-prompt-regexp prompt-regexp - comint-use-prompt-regexp t)) - (select-window (display-buffer buffer '((display-buffer-reuse-window - display-buffer-pop-up-frame) - (reusable-frames . t)))))) + comint-prompt-regexp (rx-to-string `(: bol + ,lua-ts-inferior-prompt + (1+ space)))) + (comint-read-input-ring t) + (add-hook 'comint-preoutput-filter-functions + (lambda (string) + (if (equal string (concat lua-ts-inferior-prompt-continue " ")) + string ; Don't mess with continuation prompts. + (concat + ;; Filter out the extra prompt characters that + ;; accumulate in the output when sending regions + ;; to the inferior process. + (replace-regexp-in-string (rx-to-string + `(: bol + (* ,lua-ts-inferior-prompt + (? ,lua-ts-inferior-prompt) + (1+ space)) + (group (* nonl)))) + "\\1" string) + ;; Re-add the prompt for the next line. + lua-ts-inferior-prompt " ")))))) + (select-window (display-buffer lua-ts-inferior-buffer + '((display-buffer-reuse-window + display-buffer-pop-up-frame) + (reusable-frames . t)))) + (get-buffer-process (current-buffer))) + +(defun lua-ts-send-buffer () + "Send current buffer to the inferior Lua process." + (interactive) + (lua-ts-send-region (point-min) (point-max))) + +(defun lua-ts-send-file (file) + "Send contents of FILE to the inferior Lua process." + (interactive "f") + (with-temp-buffer + (insert-file-contents-literally file) + (lua-ts-send-region (point-min) (point-max)))) + +(defun lua-ts-send-region (beg end) + "Send region between BEG and END to the inferior Lua process." + (interactive "r") + (let ((string (buffer-substring-no-properties beg end)) + (proc-buffer (lua-ts-inferior-lua))) + (comint-send-string proc-buffer "print()") ; Prevent output from + (comint-send-string proc-buffer "\n") ; appearing at prompt. + (comint-send-string proc-buffer string) + (comint-send-string proc-buffer "\n"))) + +(defun lua-ts-show-process-buffer () + "Show the inferior Lua process buffer." + (interactive) + (display-buffer lua-ts-inferior-buffer)) + +(defun lua-ts-hide-process-buffer () + "Hide the inferior Lua process buffer." + (interactive) + (delete-windows-on lua-ts-inferior-buffer)) + +(defun lua-ts-kill-process () + "Kill the inferior Lua process." + (interactive) + (with-current-buffer lua-ts-inferior-buffer + (kill-buffer-and-window))) + +(defun lua-ts-inferior--write-history (process _) + "Write history file for inferior Lua PROCESS." + ;; Depending on how the process is killed the buffer may not be + ;; around anymore; e.g. `kill-buffer'. + (when-let* ((buffer (process-buffer process)) + ((buffer-live-p (process-buffer process)))) + (with-current-buffer buffer (comint-write-input-ring)))) + +(defvar lua-ts-mode-map + (let ((map (make-sparse-keymap "Lua"))) + (define-key map "\C-c\C-n" 'lua-ts-inferior-lua) + (define-key map "\C-c\C-c" 'lua-ts-send-buffer) + (define-key map "\C-c\C-l" 'lua-ts-send-file) + (define-key map "\C-c\C-r" 'lua-ts-send-region) + map) + "Keymap for `lua-ts-mode' buffers.") + +(easy-menu-define lua-ts-mode-menu lua-ts-mode-map + "Menu bar entry for `lua-ts-mode'." + `("Lua" + ["Evaluate Buffer" lua-ts-send-buffer] + ["Evaluate File" lua-ts-send-file] + ["Evaluate Region" lua-ts-send-region] + "--" + ["Start Process" lua-ts-inferior-lua] + ["Show Process Buffer" lua-ts-show-process-buffer] + ["Hide Process Buffer" lua-ts-hide-process-buffer] + ["Kill Process" lua-ts-kill-process] + "--" + ["Customize" (lambda () (interactive) (customize-group "lua-ts"))])) ;;;###autoload (define-derived-mode lua-ts-mode prog-mode "Lua" - "Major mode for editing Lua files, powered by tree-sitter." + "Major mode for editing Lua files, powered by tree-sitter. + +\\{lua-ts-mode-map}" :syntax-table lua-ts--syntax-table + (use-local-map lua-ts-mode-map) (when (treesit-ready-p 'lua) (treesit-parser-create 'lua) @@ -404,20 +642,39 @@ lua-ts-mode (rx (or "function_declaration" "function_definition"))) (setq-local treesit-thing-settings `((lua - (sentence ,(rx (or "do_statement" - "field" - "for_statement" - "function_call" - "if_statement" - "repeat_statement" - "return_statement" - "variable_declaration" - "while_statement"))) - (sexp ,(rx (or "arguments" - "block" - "parameters" - "string" - "table_constructor"))) + (function ,(rx (or "function_declaration" + "function_definition"))) + (keyword ,(regexp-opt lua-ts--keywords + 'symbols)) + (loop-statement ,(rx (or "do_statement" + "for_statement" + "repeat_statement" + "while_statement"))) + (sentence (or function + loop-statement + ,(rx (or "assignment_statement" + "comment" + "field" + "function_call" + "if_statement" + "return_statement" + "variable_declaration")))) + (sexp (or function + keyword + loop-statement + ,(rx (or "arguments" + "break_statement" + "expression_list" + "false" + "identifier" + "nil" + "number" + "parameters" + "parenthesized_expression" + "string" + "table_constructor" + "true" + "vararg_expression")))) (text "comment")))) ;; Imenu. diff --git a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts index 040225c8580..9797467bbe5 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts @@ -5,148 +5,675 @@ Code: (lua-ts-mode) (indent-region (point-min) (point-max))) -Name: Basic Indent +Name: Chunk Indent =-= - print( -0, - 1 -) + print(1) + print(2) +=-= +print(1) +print(2) +=-=-= -local function f(o) - if o.x > o.y then - return o.x -elseif o.y > o.z then - return o.y - else -return o.z - end +Name: Function Indent + +=-= +function f1(n) +print(n) +return n + 1 end -f({ - x = 1, - y = 2, - z = 3, -}) +local function f2(n) +print(n) +return n * 2 +end -;(function() -return false -)() +local f3 = function(n) +print(n) +return n / 3 +end + +function f4(...) +local f = function (...) +if ok +then print(1) +else print(0) +end +end +return f +end + +function f5(...) +local f = function (...) +if ok +then +print(1) +else +print(0) +end +end +return f +end + +function f6(...) +local f = function (...) +if ok then +print(1) +else +print(0) +end +end +return f +end + +;(function () + return true + end)() =-= -print( - 0, - 1 -) +function f1(n) + print(n) + return n + 1 +end -local function f(o) - if o.x > o.y then - return o.x - elseif o.y > o.z then - return o.y - else - return o.z +local function f2(n) + print(n) + return n * 2 +end + +local f3 = function(n) + print(n) + return n / 3 +end + +function f4(...) + local f = function (...) + if ok + then print(1) + else print(0) + end end + return f end -f({ - x = 1, - y = 2, - z = 3, -}) +function f5(...) + local f = function (...) + if ok + then + print(1) + else + print(0) + end + end + return f +end + +function f6(...) + local f = function (...) + if ok then + print(1) + else + print(0) + end + end + return f +end -;(function() - return false -)() +;(function () + return true +end)() =-=-= -Name: Argument Indent +Name: Conditional Indent =-= -function h( -string, -number, -options) -print(string, number, options) +if true then +print(true) +return 1 +elseif false then +print(false) +return -1 +else +print(nil) +return 0 end -local p = h( -"sring", - 1000, - { -cost = 2, -length = 8, - parallelism = 4, -}) +if true + then + print(true) + return 1 + elseif false + then + print(false) + return -1 + else + print(nil) + return 0 +end + +if true + then return 1 + elseif false + then return -1 + else return 0 +end =-= -function h( - string, - number, - options) - print(string, number, options) +if true then + print(true) + return 1 +elseif false then + print(false) + return -1 +else + print(nil) + return 0 end -local p = h( - "sring", - 1000, - { - cost = 2, - length = 8, - parallelism = 4, - }) +if true +then + print(true) + return 1 +elseif false +then + print(false) + return -1 +else + print(nil) + return 0 +end + +if true +then return 1 +elseif false +then return -1 +else return 0 +end =-=-= -Name: Continuation Indent +Name: Loop Indent =-= +for k,v in pairs({}) do + print(k) + print(v) +end + +for i=1,10 + do print(i) +end + +while n < 10 do + n = n + 1 + print(n) +end + +while n < 10 + do + n = n + 1 + print(n) +end + +for i=0,9 do +repeat n = n+1 + until n > 99 +end + +repeat +z = z * 2 +print(z) +until z > 12 + + for i,x in ipairs(t) do + while i < 9 + do + local n = t[x] + repeat n = n + 1 + until n > #t + while n < 99 + do + print(n) + end + end + print(t[i]) + end + +do +local a = b +print(a + 1) +end +=-= +for k,v in pairs({}) do + print(k) + print(v) +end + +for i=1,10 +do print(i) +end + +while n < 10 do + n = n + 1 + print(n) +end + +while n < 10 +do + n = n + 1 + print(n) +end + +for i=0,9 do + repeat n = n+1 + until n > 99 +end + +repeat + z = z * 2 + print(z) +until z > 12 + +for i,x in ipairs(t) do + while i < 9 + do + local n = t[x] + repeat n = n + 1 + until n > #t + while n < 99 + do + print(n) + end + end + print(t[i]) +end + +do + local a = b + print(a + 1) +end +=-=-= + +Name: Bracket Indent + +=-= +fn( + ) + +tb={ + } +=-= +fn( +) + +tb={ +} +=-=-= + +Name: Multi-line String Indent + +=-= +local s = [[ + Multi-line + string content + ]] + function f() local str = [[ multi-line string ]] ---[[ -multi-line -comment - ]] return true end =-= +local s = [[ + Multi-line + string content + ]] + function f() local str = [[ multi-line string ]] - --[[ + return true +end +=-=-= + +Name: Multi-line Comment Indent + +=-= +--[[ + Multi-line + comment content + ]] + +function f() +--[[ +multi-line + comment + ]] + return true +end +=-= +--[[ + Multi-line + comment content + ]] + +function f() +--[[ multi-line -comment + comment ]] return true end =-=-= -Name: Loop Indent +Name: Argument Indent + +=-= + h( + "string", + 1000 + ) + +local p = h( +"string", + 1000 +) + +fn(1, +2, + 3) + +fn( 1, 2, +3, 4 ) + +f({ +x = 1, +y = 2, +z = 3, +}) + +f({ x = 1, +y = 2, +z = 3, }) + +Test({ +a=1 +}) + +Test({ +a = 1, +b = 2, +}, +nil) +=-= +h( + "string", + 1000 +) + +local p = h( + "string", + 1000 +) + +fn(1, + 2, + 3) + +fn( 1, 2, + 3, 4 ) + +f({ + x = 1, + y = 2, + z = 3, +}) + +f({ x = 1, + y = 2, + z = 3, }) + +Test({ + a=1 +}) + +Test({ + a = 1, + b = 2, + }, + nil) +=-=-= + +Name: Parameter Indent =-= -for k, v in pairs({}) do - print(k, v) +function f1( +a, +b +) +print(a,b) end -while n < 10 do -n = n + 1 +local function f2(a, + b) +print(a,b) end -repeat -z = z * 2 - until z > 12 +local f3 = function( a, b, + c, d ) +print(a,b,c,d) +end =-= -for k, v in pairs({}) do - print(k, v) +function f1( + a, + b +) + print(a,b) end -while n < 10 do - n = n + 1 +local function f2(a, + b) + print(a,b) end -repeat - z = z * 2 -until z > 12 +local f3 = function( a, b, + c, d ) + print(a,b,c,d) +end +=-=-= + +Name: Table Indent + +=-= +local Other = { + First={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Second={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Third={up={Goto=true}, + down={Goto=true}, + left={Goto=true}, + right={Goto=true}} +} + +local Other = { +a = 1, + b = 2, + c = 3, +} +=-= +local Other = { + First={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Second={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Third={up={Goto=true}, + down={Goto=true}, + left={Goto=true}, + right={Goto=true}} +} + +local Other = { + a = 1, + b = 2, + c = 3, +} +=-=-= + +Code: + (lambda () + (setq indent-tabs-mode nil) + (setq lua-ts-indent-offset 4) + (lua-ts-mode) + (indent-region (point-min) (point-max))) + +Name: End Indent + +=-= +function f(x) + for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end end end end + return {x,y} or {math.random(),math.random()} + end + +for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end + end end end +=-= +function f(x) + for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end end end end + return {x,y} or {math.random(),math.random()} +end + +for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end +end end end +=-=-= + +Name: Nested Function Indent + +=-= +function a(...) + return (function (x) + return x + end)(foo(...)) +end + +function b(n) + local x = 1 + return function (i) + return function (...) + return (function (n, ...) + return function (f, ...) + return (function (...) + if ... and x < 9 then + x = x + 1 + return ... + end end)(n(f, ...)) + end, ... + end)(i(...)) +end end end + +function c(f) + local f1 = function (...) + if nil ~= ... then + return f(...) + end + end + return function (i) + return function (...) + local fn = function (n, ...) + local x = function (f, ...) + return f1(n(f, ...)) + end + return x + end + return fn(i(...)) + end + end +end + +function d(f) + local f1 = function (c, f, ...) + if ... then + if f(...) then + return ... + else + return c(f, ...) + end end end + return function (i) + return function (...) + return (function (n, ...) + local function j (f, ...) + return f1(j, f, n(f, ...)) + end + return j, ... + end)(i(...)) +end end end + +function e (n, t) + return function (i) + return function (...) + return ( + function (n, ...) + local x, y, z = 0, {} + return (function (f, ...) + return (function (i, ...) return i(i, ...) end)( + function (i, ...) + return f(function (x, ...) + return i(i, ...)(x, ...) + end, ...) + end) + end)(function (j) + return function(f, ...) + return (function (c, f, ...) + if ... then + if n+1 == x then + local y1, x1 = y, x + y, x = {}, 0 + return (function (...) + z = ... + return ... + end)(t(y1-1, x1-1, ...)) + else + x = x - 1 + return c(f, + (function (...) + z = ... + return ... + end)(t(y, x, ...))) + end + elseif x ~= 0 then + x = 0 + return z, y + end end)(j, f, n(f, ...)) + end end), ... + end)(i(...)) +end end end =-=-= diff --git a/test/lisp/progmodes/lua-ts-mode-resources/movement.erts b/test/lisp/progmodes/lua-ts-mode-resources/movement.erts index 770aa23b18d..11e86f12926 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/movement.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/movement.erts @@ -147,7 +147,7 @@ end| print(1) =-=-= -Name: forward-sentence moves over for statements +Name: forward-sentence moves over do statements =-= |do @@ -417,34 +417,6 @@ Code: Point-Char: | -Name: forward-sexp moves over blocks - -=-= -local function Test() - |local t = { - a = 1, - } - - if true then - print(1) - else - print(0) - end -end -=-= -local function Test() - local t = { - a = 1, - } - - if true then - print(1) - else - print(0) - end| -end -=-=-= - Name: forward-sexp moves over arguments =-= @@ -481,41 +453,91 @@ local t = { 1, 3 }| =-=-= -Code: - (lambda () - (lua-ts-mode) - (backward-sexp 1)) +Name: forward-sexp moves over parenthesized expressions -Point-Char: | +=-= +|(function (x) return x + 1 end)(41) +=-= +(function (x) return x + 1 end)|(41) +=-=-= -Name: backward-sexp moves over blocks +Name: forward-sexp moves over function declarations =-= -local function Test() - local t = { - a = 1, - } +|function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end +=-= +function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end| +=-=-= - if true then - print(1) - else - print(0) - end| +Name: forward-sexp moves over do statements + +=-= +|do + print(a + 1) end =-= -local function Test() - |local t = { - a = 1, - } +do + print(a + 1) +end| +=-=-= - if true then - print(1) - else - print(0) - end +Name: forward-sexp moves over for statements + +=-= +|for k,v in pairs({}) do + print(k, v) +end +=-= +for k,v in pairs({}) do + print(k, v) +end| +=-=-= + +Name: forward-sexp moves over repeat statements + +=-= +|repeat + n = n + 1 +until n > 10 +=-= +repeat + n = n + 1 +until n > 10| +=-=-= + +Name: forward-sexp moves over while statements + +=-= +|while n < 99 +do + n = n+1 end +=-= +while n < 99 +do + n = n+1 +end| =-=-= +Code: + (lambda () + (lua-ts-mode) + (backward-sexp 1)) + +Point-Char: | + Name: backward-sexp moves over arguments =-= @@ -551,3 +573,31 @@ local t = |{ 1, 2, 3 } =-=-= + +Name: backward-sexp moves over parenthesized expressions + +=-= +(function (x) return x + 1 end)|(41) +=-= +|(function (x) return x + 1 end)(41) +=-=-= + +Name: backward-sexp moves over function declarations + +=-= +function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end| +=-= +|function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end +=-=-= -- 2.41.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Oct 17 15:37:34 2023 Received: (at 66159) by debbugs.gnu.org; 17 Oct 2023 19:37:34 +0000 Received: from localhost ([127.0.0.1]:32823 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qspsi-00017D-9C for submit@debbugs.gnu.org; Tue, 17 Oct 2023 15:37:33 -0400 Received: from out-196.mta0.migadu.com ([91.218.175.196]:51021) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qspsd-000171-IW for 66159@debbugs.gnu.org; Tue, 17 Oct 2023 15:37:30 -0400 References: <8734ynz15f.fsf@pub.pink> <87zg0u9zn2.fsf@gmail.com> <87edi6xpvn.fsf@pub.pink> <87r0m5qw2n.fsf@gmail.com> <87edi4mfu1.fsf@pub.pink> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1697571420; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=mbS3kVYradN6Qr45X2GXPFjrcQiUVXLwv/QjPuD/HS4=; b=L0myNVERBFETSXBgBGRSplL3z2L7+6FNecg/elvuhJW41lkImR0wElbT4+9V5eO5Uxi+K1 oBR+V4LskixRYQ1k8UELz78e3+UF41AAprKkF9QKbWYfWC1VcIvGWCj0asywprSizS1c+M PoUAqjVb/jVrxh/DgOgSwzaKnldpt3w= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: john muhl To: 66159@debbugs.gnu.org Subject: Re: [PATCH] Various improvements to lua-ts-mode (Bug#66159) Date: Mon, 16 Oct 2023 22:26:00 -0500 In-reply-to: <87edi4mfu1.fsf@pub.pink> Message-ID: <877cnljb1k.fsf@pub.pink> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Flow: FLOW_OUT X-Spam-Score: 0.8 (/) X-Debbugs-Envelope-To: 66159 Cc: Andrey Listopadov , Mauro Aranda X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.2 (/) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable john muhl writes: > Mauro Aranda writes: > >> On 6/10/23 16:44, john muhl via Bug reports for GNU Emacs, the Swiss >> army knife of text editors wrote: >> >>> +(defcustom lua-ts-inferior-history nil >>> + "File used to save command history of the inferior Lua process." >>> + :type '(choice (const nil) file) >> >> Please, give a :tag for the const option. IMO, it makes for a better >> Customize UI. > > Fixed here and for the other choices. > > Andrey Listopadov writes: > >> john muhl writes: >> >>>> It seems the last patch broke the movement. >>> >>> The tests for those pass and are still working here. Maybe you found >>> another case that needs to be improved. What is the specific problem? >> >> It seems so, sorry for not including this, I thought I sent this before. >> Here's an example: >> >> >> =E2=96=88for i=3D1,10 do >> print(x) >> end >> >> Pressing Pressing C-M-f (forward-sexp) puts the point here: >> >> for i=3D1,10 do >> print(x)=E2=96=88 >> end >> >> I think it should go over the `for' loop right to the `end'. >> >> Pressing Pressing C-M-b (backward-sexp), however, puts the point here: >> >> for i=3D1,10 do >> =E2=96=88print(x) >> end >> >> Pressing C-M-b again doesn't move the point anymore. >> >> Same thing happens with for-each style loop: >> >> =E2=96=88for k,v in pairs({1,2,3}) do >> print(x) >> end >> >> C-M-f: >> >> for k,v in pairs({1,2,3})=E2=96=88do >> print(x) >> end >> >> C-M-f: >> >> for k,v in pairs({1,2,3}) do >> print(x)=E2=96=88 >> end >> >> Backward movement manages to take the point way back to the pairs: >> >> C-M-b, C-M-b: >> >> for k,v in pairs=E2=96=88({1,2,3}) do >> print(x) >> end >> >> I went to https://devhints.io/lua and copied a bunch of examples of >> other loops to the scratch buffer, and the movement is as follows: >> >> =E2=96=88while condition do >> end >> >> for i =3D 1,5 do >> end >> >> for i =3D start,finish,delta do >> end >> >> for k,v in pairs(tab) do >> end >> >> repeat >> until condition >> >> -- Breaking out: >> while x do >> if condition then break end >> end >> >> C-M-f: >> >> while condition do >> end >> >> for i =3D 1,5 do >> end >> >> for i =3D start,finish,delta do >> end >> >> for k,v in pairs(tab)=E2=96=88do >> end >> >> repeat >> until condition >> >> -- Breaking out: >> while x do >> if condition then break end >> end >> >> C-M-f: >> >> while condition do >> end >> >> for i =3D 1,5 do >> end >> >> for i =3D start,finish,delta do >> end >> >> for k,v in pairs(tab) do >> end >> >> repeat >> until condition >> >> -- Breaking out: >> while x do >> if condition then break end=E2=96=88 >> end > > Navigation should be all around improved now. Let me know if I missed som= ething. > > [2. text/x-patch; 0001-Various-improvements-to-lua-ts-mode-Bug-66159.patc= h]... Here is the latest version. Fixed a missing declare-function and other minor omissions. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Various-improvements-to-lua-ts-mode-Bug-66159.patch >From 8d3b9e3617364eb9e20d489bc3979405d50abdee Mon Sep 17 00:00:00 2001 From: john muhl Date: Wed, 4 Oct 2023 20:46:15 -0500 Subject: [PATCH] Various improvements to lua-ts-mode (Bug#66159) * lisp/progmodes/lua-ts-mode.el (lua-ts-mode): Improve movement. (lua-ts--simple-indent-rules): Improve indentation rules. (lua-ts-mode-map): Add key bindings and menus. (lua-ts-mode-hook): Make hook available in Customize. (lua-ts-inferior-history): (lua-ts-inferior--write-history): Add option to read/write an input history file. (lua-ts-inferior-lua): (lua-ts-send-buffer): (lua-ts-send-file): (lua-ts-send-region): (lua-ts-inferior-prompt): (lua-ts-inferior-prompt-continue): Support for sending buffer, file or region to the inferior process. (lua-ts-show-process-buffer): (lua-ts-hide-process-buffer): (lua-ts-kill-process): New functions. (lua-ts-inferior-prompt-regexp): Remove option. * test/lisp/progmodes/lua-ts-mode-resources/indent.erts: * test/lisp/progmodes/lua-ts-mode-resources/movement.erts: Add tests. --- lisp/progmodes/lua-ts-mode.el | 382 ++++++++-- .../lua-ts-mode-resources/indent.erts | 705 +++++++++++++++--- .../lua-ts-mode-resources/movement.erts | 156 ++-- 3 files changed, 1045 insertions(+), 198 deletions(-) diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index 8db6816d6e4..2193779b759 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -38,7 +38,12 @@ (require 'cl-lib) (require 'rx)) +(declare-function treesit-induce-sparse-tree "treesit.c") (declare-function treesit-node-child-by-field-name "treesit.c") +(declare-function treesit-node-child-count "treesit.c") +(declare-function treesit-node-first-child-for-pos "treesit.c") +(declare-function treesit-node-parent "treesit.c") +(declare-function treesit-node-start "treesit.c") (declare-function treesit-node-type "treesit.c") (declare-function treesit-parser-create "treesit.c") (declare-function treesit-search-subtree "treesit.c") @@ -48,6 +53,15 @@ lua-ts :prefix "lua-ts-" :group 'languages) +(defcustom lua-ts-mode-hook nil + "Hook run after entering `lua-ts-mode'." + :type 'hook + :options '(flymake-mode + hs-minor-mode + outline-minor-mode) + :group 'lua-ts + :version "30.1") + (defcustom lua-ts-indent-offset 4 "Number of spaces for each indentation step in `lua-ts-mode'." :type 'natnum @@ -57,7 +71,7 @@ lua-ts-indent-offset (defcustom lua-ts-luacheck-program "luacheck" "Location of the Luacheck program." - :type '(choice (const nil) string) + :type '(choice (const :tag "None" nil) string) :group 'lua-ts :version "30.1") @@ -70,7 +84,7 @@ lua-ts-inferior-buffer (defcustom lua-ts-inferior-program "lua" "Program to run in the inferior Lua process." - :type '(choice (const nil) string) + :type '(choice (const :tag "None" nil) string) :group 'lua-ts :version "30.1") @@ -82,13 +96,28 @@ lua-ts-inferior-options (defcustom lua-ts-inferior-startfile nil "File to load into the inferior Lua process at startup." - :type '(choice (const nil) (file :must-match t)) + :type '(choice (const :tag "None" nil) (file :must-match t)) + :group 'lua-ts + :version "30.1") + +(defcustom lua-ts-inferior-prompt ">" + "Prompt used by the inferior Lua process." + :type 'string + :safe 'stringp + :group 'lua-ts + :version "30.1") + +(defcustom lua-ts-inferior-prompt-continue ">>" + "Continuation prompt used by the inferior Lua process." + :type 'string + :safe 'stringp :group 'lua-ts :version "30.1") -(defcustom lua-ts-inferior-prompt-regexp "^>>?[[:blank:]]" - "Regular expression matching the prompt of the inferior Lua process." - :type 'regexp +(defcustom lua-ts-inferior-history nil + "File used to save command history of the inferior Lua process." + :type '(choice (const :tag "None" nil) file) + :safe 'string-or-null-p :group 'lua-ts :version "30.1") @@ -103,6 +132,12 @@ lua-ts--builtins "close" "flush" "lines" "read" "seek" "setvbuf" "write") "Lua built-in functions for tree-sitter font-locking.") +(defvar lua-ts--keywords + '("and" "do" "else" "elseif" "end" "for" "function" + "goto" "if" "in" "local" "not" "or" "repeat" + "return" "then" "until" "while") + "Lua keywords for tree-sitter font-locking and navigation.") + (defvar lua-ts--font-lock-settings (treesit-font-lock-rules :language 'lua @@ -167,13 +202,11 @@ lua-ts--font-lock-settings :language 'lua :feature 'keyword - '((break_statement) @font-lock-keyword-face + `((break_statement) @font-lock-keyword-face (true) @font-lock-constant-face (false) @font-lock-constant-face (nil) @font-lock-constant-face - ["and" "do" "else" "elseif" "end" "for" "function" - "goto" "if" "in" "local" "not" "or" "repeat" - "return" "then" "until" "while"] + ,(vconcat lua-ts--keywords) @font-lock-keyword-face) :language 'lua @@ -235,27 +268,145 @@ lua-ts--font-lock-settings (defvar lua-ts--simple-indent-rules `((lua + ((or (node-is "comment") + (parent-is "comment_content") + (parent-is "string_content") + (node-is "]]")) + no-indent 0) + ((and (n-p-gp "field" "table_constructor" "arguments") + lua-ts--multi-arg-function-call-matcher) + parent lua-ts-indent-offset) + ((and (n-p-gp "}" "table_constructor" "arguments") + lua-ts--multi-arg-function-call-matcher) + parent 0) + ((or (node-is "do") + (node-is "then") + (node-is "elseif_statement") + (node-is "else_statement") + (node-is "until") + (node-is ")") + (node-is "}")) + standalone-parent 0) + ((or (and (parent-is "arguments") lua-ts--first-child-matcher) + (and (parent-is "parameters") lua-ts--first-child-matcher) + (and (parent-is "table_constructor") lua-ts--first-child-matcher)) + standalone-parent lua-ts-indent-offset) + ((or (parent-is "arguments") + (parent-is "parameters") + (parent-is "table_constructor")) + (nth-sibling 1) 0) + ((and (n-p-gp "block" "function_definition" "parenthesized_expression") + lua-ts--nested-function-block-matcher + lua-ts--nested-function-block-include-matcher) + parent lua-ts-indent-offset) + ((and (n-p-gp "block" "function_definition" "arguments") + lua-ts--nested-function-argument-matcher) + parent lua-ts-indent-offset) + ((match "function_definition" "parenthesized_expression") + standalone-parent lua-ts-indent-offset) + ((node-is "block") standalone-parent lua-ts-indent-offset) + ((parent-is "block") parent 0) + ((and (node-is "end") lua-ts--end-line-matcher) + standalone-parent lua-ts--end-indent-offset) + ((match "end" "function_declaration") parent 0) + ((and (n-p-gp "end" "function_definition" "parenthesized_expression") + lua-ts--nested-function-end-argument-matcher) + parent 0) + ((and (n-p-gp "end" "function_definition" "parenthesized_expression") + lua-ts--nested-function-block-matcher + lua-ts--nested-function-end-matcher + lua-ts--nested-function-last-function-matcher) + parent 0) + ((n-p-gp "end" "function_definition" "arguments") parent 0) + ((or (match "end" "function_definition") + (node-is "end")) + standalone-parent 0) + ((or (parent-is "function_declaration") + (parent-is "function_definition") + (parent-is "do_statement") + (parent-is "for_statement") + (parent-is "repeat_statement") + (parent-is "while_statement") + (parent-is "if_statement") + (parent-is "else_statement") + (parent-is "elseif_statement")) + standalone-parent lua-ts-indent-offset) ((parent-is "chunk") column-0 0) - ((node-is "comment_end") column-0 0) - ((parent-is "block") parent-bol 0) - ((node-is "}") parent-bol 0) - ((node-is ")") parent-bol 0) - ((node-is "else_statement") parent-bol 0) - ((node-is "elseif_statement") parent-bol 0) - ((node-is "end") parent-bol 0) - ((node-is "until") parent-bol 0) - ((parent-is "for_statement") parent-bol lua-ts-indent-offset) - ((parent-is "function_declaration") parent-bol lua-ts-indent-offset) - ((parent-is "function_definition") parent-bol lua-ts-indent-offset) - ((parent-is "if_statement") parent-bol lua-ts-indent-offset) - ((parent-is "else_statement") parent-bol lua-ts-indent-offset) - ((parent-is "repeat_statement") parent-bol lua-ts-indent-offset) - ((parent-is "while_statement") parent-bol lua-ts-indent-offset) - ((parent-is "table_constructor") parent-bol lua-ts-indent-offset) - ((parent-is "arguments") parent-bol lua-ts-indent-offset) - ((parent-is "parameters") parent-bol lua-ts-indent-offset) ((parent-is "ERROR") no-indent 0)))) +(defun lua-ts--end-line-matcher (&rest _) + "Matches if there is more than one `end' on the current line." + (> (lua-ts--end-count) 1)) + +(defun lua-ts--end-indent-offset (&rest _) + "Calculate indent offset based on `end' count." + (- (* (1- (lua-ts--end-count)) lua-ts-indent-offset))) + +(defun lua-ts--end-count () + "Count the number of `end's on the current line." + (count-matches "end" (line-beginning-position) (line-end-position))) + +(defun lua-ts--first-child-matcher (node &rest _) + "Matches if NODE is the first among its siblings." + (= (treesit-node-index node) 1)) + +(defun lua-ts--function-definition-p (node) + "Return t if NODE is a function_definition." + (equal "function_definition" (treesit-node-type node))) + +(defun lua-ts--g-g-g-parent (node) + "Return the great-great-grand-parent of NODE." + (let* ((parent (treesit-node-parent node)) + (g-parent (treesit-node-parent parent)) + (g-g-parent (treesit-node-parent g-parent))) + (treesit-node-parent g-g-parent))) + +(defun lua-ts--multi-arg-function-call-matcher (_n parent &rest _) + "Matches if PARENT has multiple arguments." + (> (treesit-node-child-count (treesit-node-parent parent)) 3)) + +(defun lua-ts--nested-function-argument-matcher (node &rest _) + "Matches if NODE is in a nested function argument." + (save-excursion + (goto-char (treesit-node-start node)) + (treesit-beginning-of-defun) + (backward-char 2) + (not (looking-at ")(")))) + +(defun lua-ts--nested-function-block-matcher (node &rest _) + "Matches if NODE is in a nested function block." + (let* ((g-g-g-parent (lua-ts--g-g-g-parent node)) + (g-g-g-type (treesit-node-type g-g-g-parent))) + (not (equal g-g-g-type "chunk")))) + +(defun lua-ts--nested-function-block-include-matcher (node _p bol &rest _) + "Matches if NODE's child at BOL is not another block." + (let* ((child (treesit-node-first-child-for-pos node bol)) + (child-type (treesit-node-type child)) + (g-g-g-type (treesit-node-type (lua-ts--g-g-g-parent node)))) + (or (equal child-type "assignment_statement") + (and (equal child-type "return_statement") + (or (equal g-g-g-type "arguments") + (and (equal g-g-g-type "expression_list") + (not (treesit-search-subtree child "function_call")))))))) + +(defun lua-ts--nested-function-end-matcher (node &rest _) + "Matches if NODE is the `end' of a nested function." + (save-excursion + (goto-char (treesit-node-start node)) + (treesit-beginning-of-defun) + (looking-at "function[[:space:]]*"))) + +(defun lua-ts--nested-function-end-argument-matcher (node &rest _) + "Matches if great-great-grandparent of NODE is arguments." + (equal "arguments" (treesit-node-type (lua-ts--g-g-g-parent node)))) + +(defun lua-ts--nested-function-last-function-matcher (_n parent &rest _) + "Matches if PARENT is the last nested function." + (let ((sparse-tree + (treesit-induce-sparse-tree parent #'lua-ts--function-definition-p))) + (= 1 (length (cadr sparse-tree))))) + (defvar lua-ts--syntax-table (let ((table (make-syntax-table))) (modify-syntax-entry ?+ "." table) @@ -379,26 +530,126 @@ lua-ts-flymake-luacheck (defun lua-ts-inferior-lua () "Run a Lua interpreter in an inferior process." (interactive) - (let* ((buffer lua-ts-inferior-buffer) - (name (string-replace "*" "" buffer)) - (program lua-ts-inferior-program) - (prompt-regexp lua-ts-inferior-prompt-regexp) - (switches lua-ts-inferior-options) - (startfile lua-ts-inferior-startfile)) - (unless (comint-check-proc buffer) - (set-buffer (apply (function make-comint) name program startfile switches)) + (unless (comint-check-proc lua-ts-inferior-buffer) + (apply #'make-comint-in-buffer + (string-replace "*" "" lua-ts-inferior-buffer) + lua-ts-inferior-buffer + lua-ts-inferior-program + lua-ts-inferior-startfile + lua-ts-inferior-options) + (when lua-ts-inferior-history + (set-process-sentinel (get-buffer-process lua-ts-inferior-buffer) + 'lua-ts-inferior--write-history)) + (with-current-buffer lua-ts-inferior-buffer (setq-local comint-input-ignoredups t + comint-input-ring-file-name lua-ts-inferior-history + comint-use-prompt-regexp t comint-prompt-read-only t - comint-prompt-regexp prompt-regexp - comint-use-prompt-regexp t)) - (select-window (display-buffer buffer '((display-buffer-reuse-window - display-buffer-pop-up-frame) - (reusable-frames . t)))))) + comint-prompt-regexp (rx-to-string `(: bol + ,lua-ts-inferior-prompt + (1+ space)))) + (comint-read-input-ring t) + (add-hook 'comint-preoutput-filter-functions + (lambda (string) + (if (or (not (equal (buffer-name) lua-ts-inferior-buffer)) + (equal string + (concat lua-ts-inferior-prompt-continue " "))) + string + (concat + ;; Filter out the extra prompt characters that + ;; accumulate in the output when sending regions + ;; to the inferior process. + (replace-regexp-in-string (rx-to-string + `(: bol + (* ,lua-ts-inferior-prompt + (? ,lua-ts-inferior-prompt) + (1+ space)) + (group (* nonl)))) + "\\1" string) + ;; Re-add the prompt for the next line. + lua-ts-inferior-prompt " ")))))) + (select-window (display-buffer lua-ts-inferior-buffer + '((display-buffer-reuse-window + display-buffer-pop-up-frame) + (reusable-frames . t)))) + (get-buffer-process (current-buffer))) + +(defun lua-ts-send-buffer () + "Send current buffer to the inferior Lua process." + (interactive) + (lua-ts-send-region (point-min) (point-max))) + +(defun lua-ts-send-file (file) + "Send contents of FILE to the inferior Lua process." + (interactive "f") + (with-temp-buffer + (insert-file-contents-literally file) + (lua-ts-send-region (point-min) (point-max)))) + +(defun lua-ts-send-region (beg end) + "Send region between BEG and END to the inferior Lua process." + (interactive "r") + (let ((string (buffer-substring-no-properties beg end)) + (proc-buffer (lua-ts-inferior-lua))) + (comint-send-string proc-buffer "print()") ; Prevent output from + (comint-send-string proc-buffer "\n") ; appearing at prompt. + (comint-send-string proc-buffer string) + (comint-send-string proc-buffer "\n"))) + +(defun lua-ts-show-process-buffer () + "Show the inferior Lua process buffer." + (interactive) + (display-buffer lua-ts-inferior-buffer)) + +(defun lua-ts-hide-process-buffer () + "Hide the inferior Lua process buffer." + (interactive) + (delete-windows-on lua-ts-inferior-buffer)) + +(defun lua-ts-kill-process () + "Kill the inferior Lua process." + (interactive) + (with-current-buffer lua-ts-inferior-buffer + (kill-buffer-and-window))) + +(defun lua-ts-inferior--write-history (process _) + "Write history file for inferior Lua PROCESS." + ;; Depending on how the process is killed the buffer may not be + ;; around anymore; e.g. `kill-buffer'. + (when-let* ((buffer (process-buffer process)) + ((buffer-live-p (process-buffer process)))) + (with-current-buffer buffer (comint-write-input-ring)))) + +(defvar lua-ts-mode-map + (let ((map (make-sparse-keymap "Lua"))) + (define-key map "\C-c\C-n" 'lua-ts-inferior-lua) + (define-key map "\C-c\C-c" 'lua-ts-send-buffer) + (define-key map "\C-c\C-l" 'lua-ts-send-file) + (define-key map "\C-c\C-r" 'lua-ts-send-region) + map) + "Keymap for `lua-ts-mode' buffers.") + +(easy-menu-define lua-ts-mode-menu lua-ts-mode-map + "Menu bar entry for `lua-ts-mode'." + `("Lua" + ["Evaluate Buffer" lua-ts-send-buffer] + ["Evaluate File" lua-ts-send-file] + ["Evaluate Region" lua-ts-send-region] + "--" + ["Start Process" lua-ts-inferior-lua] + ["Show Process Buffer" lua-ts-show-process-buffer] + ["Hide Process Buffer" lua-ts-hide-process-buffer] + ["Kill Process" lua-ts-kill-process] + "--" + ["Customize" (lambda () (interactive) (customize-group "lua-ts"))])) ;;;###autoload (define-derived-mode lua-ts-mode prog-mode "Lua" - "Major mode for editing Lua files, powered by tree-sitter." + "Major mode for editing Lua files, powered by tree-sitter. + +\\{lua-ts-mode-map}" :syntax-table lua-ts--syntax-table + (use-local-map lua-ts-mode-map) (when (treesit-ready-p 'lua) (treesit-parser-create 'lua) @@ -431,20 +682,39 @@ lua-ts-mode (rx (or "function_declaration" "function_definition"))) (setq-local treesit-thing-settings `((lua - (sentence ,(rx (or "do_statement" - "field" - "for_statement" - "function_call" - "if_statement" - "repeat_statement" - "return_statement" - "variable_declaration" - "while_statement"))) - (sexp ,(rx (or "arguments" - "block" - "parameters" - "string" - "table_constructor"))) + (function ,(rx (or "function_declaration" + "function_definition"))) + (keyword ,(regexp-opt lua-ts--keywords + 'symbols)) + (loop-statement ,(rx (or "do_statement" + "for_statement" + "repeat_statement" + "while_statement"))) + (sentence (or function + loop-statement + ,(rx (or "assignment_statement" + "comment" + "field" + "function_call" + "if_statement" + "return_statement" + "variable_declaration")))) + (sexp (or function + keyword + loop-statement + ,(rx (or "arguments" + "break_statement" + "expression_list" + "false" + "identifier" + "nil" + "number" + "parameters" + "parenthesized_expression" + "string" + "table_constructor" + "true" + "vararg_expression")))) (text "comment")))) ;; Imenu. diff --git a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts index 040225c8580..9797467bbe5 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts @@ -5,148 +5,675 @@ Code: (lua-ts-mode) (indent-region (point-min) (point-max))) -Name: Basic Indent +Name: Chunk Indent =-= - print( -0, - 1 -) + print(1) + print(2) +=-= +print(1) +print(2) +=-=-= -local function f(o) - if o.x > o.y then - return o.x -elseif o.y > o.z then - return o.y - else -return o.z - end +Name: Function Indent + +=-= +function f1(n) +print(n) +return n + 1 end -f({ - x = 1, - y = 2, - z = 3, -}) +local function f2(n) +print(n) +return n * 2 +end -;(function() -return false -)() +local f3 = function(n) +print(n) +return n / 3 +end + +function f4(...) +local f = function (...) +if ok +then print(1) +else print(0) +end +end +return f +end + +function f5(...) +local f = function (...) +if ok +then +print(1) +else +print(0) +end +end +return f +end + +function f6(...) +local f = function (...) +if ok then +print(1) +else +print(0) +end +end +return f +end + +;(function () + return true + end)() =-= -print( - 0, - 1 -) +function f1(n) + print(n) + return n + 1 +end -local function f(o) - if o.x > o.y then - return o.x - elseif o.y > o.z then - return o.y - else - return o.z +local function f2(n) + print(n) + return n * 2 +end + +local f3 = function(n) + print(n) + return n / 3 +end + +function f4(...) + local f = function (...) + if ok + then print(1) + else print(0) + end end + return f end -f({ - x = 1, - y = 2, - z = 3, -}) +function f5(...) + local f = function (...) + if ok + then + print(1) + else + print(0) + end + end + return f +end + +function f6(...) + local f = function (...) + if ok then + print(1) + else + print(0) + end + end + return f +end -;(function() - return false -)() +;(function () + return true +end)() =-=-= -Name: Argument Indent +Name: Conditional Indent =-= -function h( -string, -number, -options) -print(string, number, options) +if true then +print(true) +return 1 +elseif false then +print(false) +return -1 +else +print(nil) +return 0 end -local p = h( -"sring", - 1000, - { -cost = 2, -length = 8, - parallelism = 4, -}) +if true + then + print(true) + return 1 + elseif false + then + print(false) + return -1 + else + print(nil) + return 0 +end + +if true + then return 1 + elseif false + then return -1 + else return 0 +end =-= -function h( - string, - number, - options) - print(string, number, options) +if true then + print(true) + return 1 +elseif false then + print(false) + return -1 +else + print(nil) + return 0 end -local p = h( - "sring", - 1000, - { - cost = 2, - length = 8, - parallelism = 4, - }) +if true +then + print(true) + return 1 +elseif false +then + print(false) + return -1 +else + print(nil) + return 0 +end + +if true +then return 1 +elseif false +then return -1 +else return 0 +end =-=-= -Name: Continuation Indent +Name: Loop Indent =-= +for k,v in pairs({}) do + print(k) + print(v) +end + +for i=1,10 + do print(i) +end + +while n < 10 do + n = n + 1 + print(n) +end + +while n < 10 + do + n = n + 1 + print(n) +end + +for i=0,9 do +repeat n = n+1 + until n > 99 +end + +repeat +z = z * 2 +print(z) +until z > 12 + + for i,x in ipairs(t) do + while i < 9 + do + local n = t[x] + repeat n = n + 1 + until n > #t + while n < 99 + do + print(n) + end + end + print(t[i]) + end + +do +local a = b +print(a + 1) +end +=-= +for k,v in pairs({}) do + print(k) + print(v) +end + +for i=1,10 +do print(i) +end + +while n < 10 do + n = n + 1 + print(n) +end + +while n < 10 +do + n = n + 1 + print(n) +end + +for i=0,9 do + repeat n = n+1 + until n > 99 +end + +repeat + z = z * 2 + print(z) +until z > 12 + +for i,x in ipairs(t) do + while i < 9 + do + local n = t[x] + repeat n = n + 1 + until n > #t + while n < 99 + do + print(n) + end + end + print(t[i]) +end + +do + local a = b + print(a + 1) +end +=-=-= + +Name: Bracket Indent + +=-= +fn( + ) + +tb={ + } +=-= +fn( +) + +tb={ +} +=-=-= + +Name: Multi-line String Indent + +=-= +local s = [[ + Multi-line + string content + ]] + function f() local str = [[ multi-line string ]] ---[[ -multi-line -comment - ]] return true end =-= +local s = [[ + Multi-line + string content + ]] + function f() local str = [[ multi-line string ]] - --[[ + return true +end +=-=-= + +Name: Multi-line Comment Indent + +=-= +--[[ + Multi-line + comment content + ]] + +function f() +--[[ +multi-line + comment + ]] + return true +end +=-= +--[[ + Multi-line + comment content + ]] + +function f() +--[[ multi-line -comment + comment ]] return true end =-=-= -Name: Loop Indent +Name: Argument Indent + +=-= + h( + "string", + 1000 + ) + +local p = h( +"string", + 1000 +) + +fn(1, +2, + 3) + +fn( 1, 2, +3, 4 ) + +f({ +x = 1, +y = 2, +z = 3, +}) + +f({ x = 1, +y = 2, +z = 3, }) + +Test({ +a=1 +}) + +Test({ +a = 1, +b = 2, +}, +nil) +=-= +h( + "string", + 1000 +) + +local p = h( + "string", + 1000 +) + +fn(1, + 2, + 3) + +fn( 1, 2, + 3, 4 ) + +f({ + x = 1, + y = 2, + z = 3, +}) + +f({ x = 1, + y = 2, + z = 3, }) + +Test({ + a=1 +}) + +Test({ + a = 1, + b = 2, + }, + nil) +=-=-= + +Name: Parameter Indent =-= -for k, v in pairs({}) do - print(k, v) +function f1( +a, +b +) +print(a,b) end -while n < 10 do -n = n + 1 +local function f2(a, + b) +print(a,b) end -repeat -z = z * 2 - until z > 12 +local f3 = function( a, b, + c, d ) +print(a,b,c,d) +end =-= -for k, v in pairs({}) do - print(k, v) +function f1( + a, + b +) + print(a,b) end -while n < 10 do - n = n + 1 +local function f2(a, + b) + print(a,b) end -repeat - z = z * 2 -until z > 12 +local f3 = function( a, b, + c, d ) + print(a,b,c,d) +end +=-=-= + +Name: Table Indent + +=-= +local Other = { + First={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Second={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Third={up={Goto=true}, + down={Goto=true}, + left={Goto=true}, + right={Goto=true}} +} + +local Other = { +a = 1, + b = 2, + c = 3, +} +=-= +local Other = { + First={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Second={up={Step=true,Jump=true}, + down={Step=true,Jump=true}, + left={Step=true,Jump=true}, + right={Step=true,Jump=true}}, + Third={up={Goto=true}, + down={Goto=true}, + left={Goto=true}, + right={Goto=true}} +} + +local Other = { + a = 1, + b = 2, + c = 3, +} +=-=-= + +Code: + (lambda () + (setq indent-tabs-mode nil) + (setq lua-ts-indent-offset 4) + (lua-ts-mode) + (indent-region (point-min) (point-max))) + +Name: End Indent + +=-= +function f(x) + for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end end end end + return {x,y} or {math.random(),math.random()} + end + +for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end + end end end +=-= +function f(x) + for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end end end end + return {x,y} or {math.random(),math.random()} +end + +for y=1,x.y do + for x=1,x.z do + if x.y and x.z then + if y <= x then + y = y + 1 + end +end end end +=-=-= + +Name: Nested Function Indent + +=-= +function a(...) + return (function (x) + return x + end)(foo(...)) +end + +function b(n) + local x = 1 + return function (i) + return function (...) + return (function (n, ...) + return function (f, ...) + return (function (...) + if ... and x < 9 then + x = x + 1 + return ... + end end)(n(f, ...)) + end, ... + end)(i(...)) +end end end + +function c(f) + local f1 = function (...) + if nil ~= ... then + return f(...) + end + end + return function (i) + return function (...) + local fn = function (n, ...) + local x = function (f, ...) + return f1(n(f, ...)) + end + return x + end + return fn(i(...)) + end + end +end + +function d(f) + local f1 = function (c, f, ...) + if ... then + if f(...) then + return ... + else + return c(f, ...) + end end end + return function (i) + return function (...) + return (function (n, ...) + local function j (f, ...) + return f1(j, f, n(f, ...)) + end + return j, ... + end)(i(...)) +end end end + +function e (n, t) + return function (i) + return function (...) + return ( + function (n, ...) + local x, y, z = 0, {} + return (function (f, ...) + return (function (i, ...) return i(i, ...) end)( + function (i, ...) + return f(function (x, ...) + return i(i, ...)(x, ...) + end, ...) + end) + end)(function (j) + return function(f, ...) + return (function (c, f, ...) + if ... then + if n+1 == x then + local y1, x1 = y, x + y, x = {}, 0 + return (function (...) + z = ... + return ... + end)(t(y1-1, x1-1, ...)) + else + x = x - 1 + return c(f, + (function (...) + z = ... + return ... + end)(t(y, x, ...))) + end + elseif x ~= 0 then + x = 0 + return z, y + end end)(j, f, n(f, ...)) + end end), ... + end)(i(...)) +end end end =-=-= diff --git a/test/lisp/progmodes/lua-ts-mode-resources/movement.erts b/test/lisp/progmodes/lua-ts-mode-resources/movement.erts index 770aa23b18d..11e86f12926 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/movement.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/movement.erts @@ -147,7 +147,7 @@ end| print(1) =-=-= -Name: forward-sentence moves over for statements +Name: forward-sentence moves over do statements =-= |do @@ -417,34 +417,6 @@ Code: Point-Char: | -Name: forward-sexp moves over blocks - -=-= -local function Test() - |local t = { - a = 1, - } - - if true then - print(1) - else - print(0) - end -end -=-= -local function Test() - local t = { - a = 1, - } - - if true then - print(1) - else - print(0) - end| -end -=-=-= - Name: forward-sexp moves over arguments =-= @@ -481,41 +453,91 @@ local t = { 1, 3 }| =-=-= -Code: - (lambda () - (lua-ts-mode) - (backward-sexp 1)) +Name: forward-sexp moves over parenthesized expressions -Point-Char: | +=-= +|(function (x) return x + 1 end)(41) +=-= +(function (x) return x + 1 end)|(41) +=-=-= -Name: backward-sexp moves over blocks +Name: forward-sexp moves over function declarations =-= -local function Test() - local t = { - a = 1, - } +|function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end +=-= +function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end| +=-=-= - if true then - print(1) - else - print(0) - end| +Name: forward-sexp moves over do statements + +=-= +|do + print(a + 1) end =-= -local function Test() - |local t = { - a = 1, - } +do + print(a + 1) +end| +=-=-= - if true then - print(1) - else - print(0) - end +Name: forward-sexp moves over for statements + +=-= +|for k,v in pairs({}) do + print(k, v) +end +=-= +for k,v in pairs({}) do + print(k, v) +end| +=-=-= + +Name: forward-sexp moves over repeat statements + +=-= +|repeat + n = n + 1 +until n > 10 +=-= +repeat + n = n + 1 +until n > 10| +=-=-= + +Name: forward-sexp moves over while statements + +=-= +|while n < 99 +do + n = n+1 end +=-= +while n < 99 +do + n = n+1 +end| =-=-= +Code: + (lambda () + (lua-ts-mode) + (backward-sexp 1)) + +Point-Char: | + Name: backward-sexp moves over arguments =-= @@ -551,3 +573,31 @@ local t = |{ 1, 2, 3 } =-=-= + +Name: backward-sexp moves over parenthesized expressions + +=-= +(function (x) return x + 1 end)|(41) +=-= +|(function (x) return x + 1 end)(41) +=-=-= + +Name: backward-sexp moves over function declarations + +=-= +function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end| +=-= +|function foo (x) + if false then + print "foo" + elseif true then + print "bar" + end +end +=-=-= -- 2.41.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Oct 20 16:40:53 2023 Received: (at 66159) by debbugs.gnu.org; 20 Oct 2023 20:40:53 +0000 Received: from localhost ([127.0.0.1]:41723 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtwIf-0005DT-3i for submit@debbugs.gnu.org; Fri, 20 Oct 2023 16:40:53 -0400 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]:46560) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtwId-0005DA-7O for 66159@debbugs.gnu.org; Fri, 20 Oct 2023 16:40:51 -0400 Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2c50305c5c4so18746371fa.1 for <66159@debbugs.gnu.org>; Fri, 20 Oct 2023 13:40:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697834418; x=1698439218; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:from:to:cc:subject:date:message-id:reply-to; bh=aTuK3oWrVIr76Qd5N43PyZ0wyF8fzR75d2z6p/FSj5w=; b=hZLGhiXJWZ5jHlNMFNSYc8GqkMv1P/eJwDzzfE2LLcmZK8U2S1YdRDwBGbOtV8jWqf JAVrgMkBM7DYessSbn2bx3pqQMOpL2B0+ODQXq1RsJErpTjtREajwgpQwKqQGIHFmRSD XY8PfOJftXcD64orXAfjlHJeelPVktILVjX20JnUeF2L9l8ffSvJIaasRGQT6alAw2fX camD0q71MZv8YZB1flm6RaclH6EAhi4n9wGeZkE1gpOAR+uCszEuLTx0tkMzQVETPBJi E8ItS3E9kPyI2ZbZH/0HxrXxH3XQkUqRJiDL1Jju+5FeTi596J5HStqFaVX1riJ01HjE XpbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697834418; x=1698439218; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aTuK3oWrVIr76Qd5N43PyZ0wyF8fzR75d2z6p/FSj5w=; b=FsyjyM5rTBaw/J9nfzmzQEIVTOzRCjhNiOewmBeP/Rla54v2Js9VJGXuNbmVmMFgiI dH3ZZMav6j1dmV9+J/e2LcdIoepWY3f0Kp3Dj/2s6LN6ONahQ0aIM6WHJd5IyFR8azbC ZJclhfqcCtUko5qtXZ2OpBM5EjMnmYm3Kr3FxxMVoZUxQBG0Mii0AP7VMyw7SPHLH4N+ kpb99Eo6CVWXqCg3bYVGnwnPV7KXVQEs9dAu8YebRCR7t8uZr4RUhh6xJEVmWgS4feqG RXtez+vIAFHI/TFZOnH/oVFYG20f1u+vM+DhAt+ZGoqAGUlC8xocz5zQyDE5GT8KuBFX Vd4A== X-Gm-Message-State: AOJu0Yzz19bwxl1mRoxxBpNitanXfow0e1HSvTUKA3RbKKvHg5aoN3q9 TFJ/DFmUmn7FyWrHjf1hUkL0gU5r6TPx83XsyRE= X-Google-Smtp-Source: AGHT+IEiS3yWx7w/R/PS0zi6odQcJK79a/KE2qZAQyyFTxkSDSlmPbvdkO7FPeD7s4BEqnKbizSxam0Lu9d7hfTv7Sw= X-Received: by 2002:a2e:a543:0:b0:2c5:634:b45e with SMTP id e3-20020a2ea543000000b002c50634b45emr2199570ljn.36.1697834417492; Fri, 20 Oct 2023 13:40:17 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Fri, 20 Oct 2023 13:40:17 -0700 From: Stefan Kangas In-Reply-To: <877cnljb1k.fsf@pub.pink> References: <8734ynz15f.fsf@pub.pink> <87zg0u9zn2.fsf@gmail.com> <87edi6xpvn.fsf@pub.pink> <87r0m5qw2n.fsf@gmail.com> <87edi4mfu1.fsf@pub.pink> <877cnljb1k.fsf@pub.pink> MIME-Version: 1.0 Date: Fri, 20 Oct 2023 13:40:17 -0700 Message-ID: Subject: Re: bug#66159: [PATCH] Various improvements to lua-ts-mode (Bug#66159) To: john muhl , 66159@debbugs.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159 Cc: Andrey Listopadov , Mauro Aranda X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) john muhl via "Bug reports for GNU Emacs, the Swiss army knife of text editors" writes: > Here is the latest version. Fixed a missing declare-function > and other minor omissions. Thanks. Is this ready for installing on master, or is there anything else that needs doing first? From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 21 01:15:53 2023 Received: (at 66159) by debbugs.gnu.org; 21 Oct 2023 05:15:53 +0000 Received: from localhost ([127.0.0.1]:42067 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qu4L1-00029V-Ky for submit@debbugs.gnu.org; Sat, 21 Oct 2023 01:15:53 -0400 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]:43025) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qu4Ku-000299-Dt for 66159@debbugs.gnu.org; Sat, 21 Oct 2023 01:15:50 -0400 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-507cd62472dso2950903e87.0 for <66159@debbugs.gnu.org>; Fri, 20 Oct 2023 22:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697865311; x=1698470111; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=G0n+kuOohONhsIoU5n978TdsvBWQrZwwga7PxpP07mg=; b=EwhT9PSCxIwHLFbWNiUTZNMjMSI4anDou6t5BAoKQNsbNZBQ8zGKlen67WNDtK1/+u eG2lLazld/pYd+dzsySTyfwZBl4kW89xt3ZzLkoZp1st1WeTQNP6F43/j+dVtzuXD+Fb 3l8Nn9l7xzOlv6B8ZyBU/YsjrME1BR+zbAMH2sYeuI6c+3DhF+F+YzFgsIKtwdlioqC7 8akiEHumo4AOJJmhZqq6zksW372qc41VAFNSkPgZAzOeVLAp65kQRH1TIpfiOdd7FwZ+ SYAnsUaF0Mv5hqi95GpkI6myl0fvjrVTiNG8h6jiforhRk8F8rKtL1N0P10XYuKG/NFv tkLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697865311; x=1698470111; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=G0n+kuOohONhsIoU5n978TdsvBWQrZwwga7PxpP07mg=; b=jAUdoW0SaPuwiHJx2iI5HjLKSUEs2NQBMbr5Iem+UPaEGRby/nh7GHH9OfY4i0cgBz +UmzZMX9D7fN42sY1vrzeVPnXmHI95bQARD8doEfLAulZRgwcciEhhGE0c6pXmVU/jdd N/ttWA6anJ7UpGqlTShjNIm08S7aNi40yKUIqxXA4n+IgtbntAEjJzO0eVpc1mtYRepX N2kyWzm9JsxF+t4ex7oyi8EUcO+h7S3dmjh+Jj7faSfLe4oJbwy5L8OtPHqnZaCBjEaB zbCpDeLcd05Fagfs+61sIWjQEwoKGMY4stCgOfIVzMhyZfFX5bmEEZ7eKSaxHKiDSeLC t+qQ== X-Gm-Message-State: AOJu0YyFrcngMt9ubZv5swsBzhR24nlQSMWMfyy4eGNKzRq/s/lQpZE2 VwevI6fSjvfIf4oIlB4nHY4= X-Google-Smtp-Source: AGHT+IEpHJC/g8yzk53nPMhK9ULbBlyazhqhxut+y9K4CHxvLVZRc8Dv3cgbec3z3iphAPjpQ2vXYA== X-Received: by 2002:ac2:528a:0:b0:503:7f6:ac20 with SMTP id q10-20020ac2528a000000b0050307f6ac20mr1262796lfm.5.1697865310433; Fri, 20 Oct 2023 22:15:10 -0700 (PDT) Received: from [127.0.0.1] ([176.59.13.157]) by smtp.gmail.com with ESMTPSA id m3-20020ac24283000000b00502e01d1383sm697567lfh.27.2023.10.20.22.15.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Oct 2023 22:15:10 -0700 (PDT) Date: Sat, 21 Oct 2023 08:15:06 +0300 From: Andrey To: john muhl , 66159@debbugs.gnu.org Subject: Re: [PATCH] Various improvements to lua-ts-mode (Bug#66159) User-Agent: K-9 Mail for Android In-Reply-To: <877cnljb1k.fsf@pub.pink> References: <8734ynz15f.fsf@pub.pink> <87zg0u9zn2.fsf@gmail.com> <87edi6xpvn.fsf@pub.pink> <87r0m5qw2n.fsf@gmail.com> <87edi4mfu1.fsf@pub.pink> <877cnljb1k.fsf@pub.pink> Message-ID: <0715E2B6-4B98-4543-9643-FB2F8763EE16@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159 Cc: Mauro Aranda X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) >Here is the latest version=2E Fixed a missing declare-function >and other minor omissions=2E > Thanks! Unfortunately, I'm on the trip right now and can't check the patch= =2E Sorry for delay=2E The last patch was great, so I have no objections from = my part=2E --=20 Andrey Listopadov From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 21 07:38:38 2023 Received: (at 66159) by debbugs.gnu.org; 21 Oct 2023 11:38:38 +0000 Received: from localhost ([127.0.0.1]:42418 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1quAJS-0008Lw-7I for submit@debbugs.gnu.org; Sat, 21 Oct 2023 07:38:38 -0400 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]:59894) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1quAJN-0008Lg-W4 for 66159@debbugs.gnu.org; Sat, 21 Oct 2023 07:38:37 -0400 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-507adc3381cso2439666e87.3 for <66159@debbugs.gnu.org>; Sat, 21 Oct 2023 04:38:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697888280; x=1698493080; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=xFkb6uo+grul7EmZ3DehJTohIZUJoEXzmRrJKO9IrPM=; b=hJlHJ2kH0rfvaleMHRNEF/jFk8Vp5nwFFSLwOXQOYUnjTcrxemxNjU2GZwNz57ESzR 0nVBm1iMb+Xc7F+lE1b16keVvwAgQWgInhOkW8cZpbsmml18OcBBgxaoulq5UcSeJXJr FgR9BroyvDtT1+q0B592wZA84SCj8tr3ILw4MjNsBmSd33B06ck38bOSDuS2qypRYdOO Pz0whT+/ZA8bj/RNBRGfUxMHbI5x1ok8XfIzH5nCkxo4j2vyavZlTcvaJwS6A2Vei9ne Z0aymIjyRGbzpJomVIX3ovbfCrOL2CCnBPc1Fpnt0zdOs5InlxJXsDbEznvkvesMkViH I2RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697888280; x=1698493080; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=xFkb6uo+grul7EmZ3DehJTohIZUJoEXzmRrJKO9IrPM=; b=gZ3hQsQQ+jmtmCSWVYvpth5HISrvShV7froCgiUOY73froKlZFz0YTptwCGgfm92ye UwWkiUdqVl2Ny7qkrMqS9IeLwliMTvdNTca2MmEQ0L/5m4PeIl0RxN4V7AmK5chy31lZ Hy+oCv44fKO4SLAf3X/95cSFodA1kpN5qVReslBDIpDA8XsgzLi7T4Z5Bro3GZYYyMva 0PSAXPPZUlrWUVOGt75bYh7Rzcz87GTshNprQayvswCBZ8LlGxwFZPc7O0z6ThPuclLi qF8mC8HPyOPlaXkk+HJkRijZbv7BOukcG+93h6rjXRA/71XLzH0gWL8EpE7mg8er3h/P MG1A== X-Gm-Message-State: AOJu0YwxH/+oDFqOy6X0g3vbBAgYcgOWDNYOqpLbz8jpdPGSZ7wDp6z7 NgQK5o0+Mvn/pBjy3+7WVhc= X-Google-Smtp-Source: AGHT+IE0sR3VVUEQkQIf0v8/vrOamWsP46nCQEhWbSfS/p/EDiZdKopczko3kkbXuu1hk/d6U2QUog== X-Received: by 2002:ac2:4d06:0:b0:502:ab7b:e480 with SMTP id r6-20020ac24d06000000b00502ab7be480mr2588154lfi.36.1697888279534; Sat, 21 Oct 2023 04:37:59 -0700 (PDT) Received: from [127.0.0.1] ([176.59.18.10]) by smtp.gmail.com with ESMTPSA id n24-20020a05651203f800b00501c8959f6asm836083lfq.98.2023.10.21.04.37.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Oct 2023 04:37:59 -0700 (PDT) Date: Sat, 21 Oct 2023 14:37:57 +0300 From: Andrey To: john muhl , 66159@debbugs.gnu.org Subject: Re: [PATCH] Various improvements to lua-ts-mode (Bug#66159) User-Agent: K-9 Mail for Android In-Reply-To: <877cnljb1k.fsf@pub.pink> References: <8734ynz15f.fsf@pub.pink> <87zg0u9zn2.fsf@gmail.com> <87edi6xpvn.fsf@pub.pink> <87r0m5qw2n.fsf@gmail.com> <87edi4mfu1.fsf@pub.pink> <877cnljb1k.fsf@pub.pink> Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159 Cc: Mauro Aranda X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) >Here is the latest version=2E Fixed a missing declare-function >and other minor omissions=2E > Thanks! Unfortunately, I'm on the trip right now and can't check the patch= =2E Sorry for delay=2E The last patch was great, so I have no objections from = my part=2E --=20 Andrey Listopadov --=20 Andrey Listopadov From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 23 00:31:01 2023 Received: (at 66159) by debbugs.gnu.org; 23 Oct 2023 04:31:01 +0000 Received: from localhost ([127.0.0.1]:48779 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qumaj-00037B-F3 for submit@debbugs.gnu.org; Mon, 23 Oct 2023 00:31:01 -0400 Received: from out-205.mta0.migadu.com ([91.218.175.205]:21087) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qumad-00036s-7t for 66159@debbugs.gnu.org; Mon, 23 Oct 2023 00:30:59 -0400 References: <8734ynz15f.fsf@pub.pink> <87zg0u9zn2.fsf@gmail.com> <87edi6xpvn.fsf@pub.pink> <87r0m5qw2n.fsf@gmail.com> <87edi4mfu1.fsf@pub.pink> <877cnljb1k.fsf@pub.pink> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1698035424; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dgg0s3/v1ftSN/zgVbysVBnmALCR5+DeKXRm3/0OgLU=; b=X8dEoc9jMCCPSs37/TxAp4FBecV/8y/Q2IMaNzOxEH6yvUEr6v9F4gmVRMQIzMVSvDnHNv 0EWPN+HE+qDn48OvihSomVZ4yrmhndZKbMVGL6KtuDgCC8yG1X+d5B3BHDgpBEQzfcEaNl 9QDAR6QgdpCX4NGanZLAYUGidyEJAZI= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: john muhl To: Stefan Kangas Subject: Re: bug#66159: [PATCH] Various improvements to lua-ts-mode (Bug#66159) Date: Sun, 22 Oct 2023 15:03:47 -0500 In-reply-to: Message-ID: <87zg0aj6zn.fsf@pub.pink> MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Flow: FLOW_OUT X-Spam-Score: 1.1 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Stefan Kangas writes: > john muhl via "Bug reports for GNU Emacs, the Swiss army knife of text > editors" writes: > >> Here is the latest version. Fixed a missing declare-function >> and other minor [...] Content analysis details: (1.1 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 1.1 DATE_IN_PAST_06_12 Date: is 6 to 12 hours before Received: date X-Debbugs-Envelope-To: 66159 Cc: 66159@debbugs.gnu.org, Andrey Listopadov , Mauro Aranda X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.1 (/) Stefan Kangas writes: > john muhl via "Bug reports for GNU Emacs, the Swiss army knife of text > editors" writes: > >> Here is the latest version. Fixed a missing declare-function >> and other minor omissions. > > Thanks. Is this ready for installing on master, or is there anything > else that needs doing first? It should be ok to install. From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 23 04:12:35 2023 Received: (at 66159-done) by debbugs.gnu.org; 23 Oct 2023 08:12:35 +0000 Received: from localhost ([127.0.0.1]:48995 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1quq39-0001yf-CL for submit@debbugs.gnu.org; Mon, 23 Oct 2023 04:12:35 -0400 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]:48493) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1quq37-0001yR-Nm for 66159-done@debbugs.gnu.org; Mon, 23 Oct 2023 04:12:34 -0400 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-5079f3f3d7aso4658086e87.1 for <66159-done@debbugs.gnu.org>; Mon, 23 Oct 2023 01:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698048718; x=1698653518; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:from:to:cc:subject:date:message-id:reply-to; bh=67vYTYF/Jt/AePssVuE7ZPMPHHaz/AFh48B/619G6QQ=; b=Hu2H3ahmPlkO7QL7RP2v4g3U5NRLrZnW+OERxJs1iCjhFATOCQbOqs/IdsSuYuwCaJ utUhQu2cgVaIlivyZdvXgILq0HQvuzS9qx14WTzo2JVxGs/bXGTBZsFJXLsudOYrfx0A 3nJrC1MZDIl5qmZQfvFY4AJ2q6PyQ8fajeuHZjwJz1pAyWsLVdaXy4w+G7+H3+pfD4Gt itXhyVI6exsRiua/YBe+XVI58GWn/FzFT6U+eGnc3m1vGT8VeXyytFoszybZi8IjVvp4 ld7+exrt7OARGHKM88pC/7Mye85FQGILMIpfTBXZ2O+o598lNUMJQOqhBk75yVYwxfXn vaUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698048718; x=1698653518; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=67vYTYF/Jt/AePssVuE7ZPMPHHaz/AFh48B/619G6QQ=; b=qnq3QO6jAh/4Pqwm+VpHErRr++RLZKZOqrK9s+fHhvnC/r3Lag6sls9o4zsfAZn6Rl On7g3xWenid5/d1bwwCSBjxm9tPH5ECzV1fMVs3Y2dEe9iYVFAvI7YN3RtkQwrZdiRSg 6zh4rBtfTe4UXZJK7MVkY4ULdy5J694SQNPc8HWZwIrMJzDS8q6Fd4qWcidzdj5e2Se7 ouHkqeaFe4hpPLFvezj7Mb3G+QwTN3pS4lCUi4DM848i0RBrAhh824AoTsAsc6lWc40w nQz4z3hz+kl8f/CydQhMR5O5Wb2pCxgYdsCj0gUCXX/H+KxfSMFnezLWztk5IUzKE9Cv dDfQ== X-Gm-Message-State: AOJu0Yy72ogiWCE8X2NxmKEYVlS4E4IHh4crbw3KQPCTYtMvPFmDi707 zflPiikkRvToKIZ5b+XR2v9BoXSeI4qTjpCx8J0= X-Google-Smtp-Source: AGHT+IHSPp+Z28B8SQ/Cl93yrxx+BF/JfPofN2hB1UKQV7LiziQs5Gvqf6E3iIKVMJkAj0OR0NMoT2MWFM7O6NNpg6I= X-Received: by 2002:a05:651c:1184:b0:2b6:de52:357 with SMTP id w4-20020a05651c118400b002b6de520357mr4972193ljo.40.1698048718375; Mon, 23 Oct 2023 01:11:58 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Mon, 23 Oct 2023 01:11:57 -0700 From: Stefan Kangas In-Reply-To: <87zg0aj6zn.fsf@pub.pink> References: <8734ynz15f.fsf@pub.pink> <87zg0u9zn2.fsf@gmail.com> <87edi6xpvn.fsf@pub.pink> <87r0m5qw2n.fsf@gmail.com> <87edi4mfu1.fsf@pub.pink> <877cnljb1k.fsf@pub.pink> <87zg0aj6zn.fsf@pub.pink> MIME-Version: 1.0 Date: Mon, 23 Oct 2023 01:11:57 -0700 Message-ID: Subject: Re: bug#66159: [PATCH] Various improvements to lua-ts-mode (Bug#66159) To: john muhl Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66159-done Cc: 66159-done@debbugs.gnu.org, Andrey Listopadov , Mauro Aranda X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Version: 30.1 john muhl writes: > It should be ok to install. Thanks, installed on master. I'm consequently closing this bug. [1: 1c261e0a6ca]: 2023-10-23 10:07:52 +0200 Various improvements to lua-ts-mode (Bug#66159) https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=1c261e0a6cae09e3ff36930442f2c9da44bccd6d From unknown Fri Aug 15 17:22:20 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 20 Nov 2023 12:24:09 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator