Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic matlab support #289

Merged
merged 4 commits into from
Sep 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
![Dumb Jump GIF](media/dumb-jump-example-v2.gif?raw=true)

## About
**Dumb Jump** is an Emacs "jump to definition" package with support for multiple programming languages that favors "just working". This means minimal -- and ideally zero -- configuration with absolutely no stored indexes (TAGS) or persistent background processes. Dumb Jump requires at least GNU Emacs `24.3`.
**Dumb Jump** is an Emacs "jump to definition" package with support for 40+ programming languages that favors "just working". This means minimal -- and ideally zero -- configuration with absolutely no stored indexes (TAGS) or persistent background processes. Dumb Jump requires at least GNU Emacs `24.3`.


#### How it works
Expand Down Expand Up @@ -41,6 +41,7 @@ There is currently basic support for the following languages:
* Julia
* LaTeX
* Lua
* Matlab
* Nim
* Nix
* Objective-C
Expand Down
43 changes: 34 additions & 9 deletions dumb-jump.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; dumb-jump.el --- jump to definition for multiple languages without configuration. -*- lexical-binding: t; -*-
;; Copyright (C) 2015-2018 jack angers
;; Author: jack angers
;; Copyright (C) 2015-2019 jack angers
;; Author: jack angers and contributors
;; Version: 0.5.2
;; Package-Requires: ((emacs "24.3") (f "0.20.0") (s "1.11.0") (dash "2.9.0") (popup "0.5.3"))
;; Keywords: programming
Expand Down Expand Up @@ -68,7 +68,7 @@

(defcustom dumb-jump-ivy-jump-to-selected-function
#'dumb-jump-ivy-jump-to-selected
"Prompts user for a choice using ivy then dumb-jump to that choice")
"Prompts user for a choice using ivy then dumb-jump to that choice.")

(defcustom dumb-jump-prefer-searcher
nil
Expand All @@ -82,7 +82,6 @@ If nil then the most optimal searcher will be chosen at runtime."
(const :tag "git grep" git-grep)
(const :tag "git grep + ag" git-grep-plus-ag)))


(defcustom dumb-jump-force-searcher
nil
"Forcibly use searcher: 'ag, 'rg, 'git-grep, 'gnu-grep, or 'grep.
Expand Down Expand Up @@ -526,6 +525,22 @@ or most optimal searcher."
:tests ("class test(object):" "class test:")
:not ("class testnot:" "class testnot(object):"))

;; matlab
(:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "matlab"
:regex "^\\s*\\bJJJ\\s*=[^=\\n]+"
:tests ("test = 1234")
:not ("for test = 1:2:" "_test = 1234"))

(:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "matlab"
:regex "^\\s*function\\s*[^=]+\\s*=\\s*JJJ\\b"
:tests ("\tfunction y = test(asdf)" "function x = test()" "function [x, losses] = test(A, y, lambda, method, qtile)")
:not ("\tfunction testnot(asdf)" "function testnot()"))

(:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "matlab"
:regex "^\\s*classdef\\s*JJJ\\b\\s*"
:tests ("classdef test")
:not ("classdef testnot"))

;; nim
(:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "nim"
:regex "(const|let|var)\\s*JJJ\\s*(=|:)[^=:\\n]+"
Expand Down Expand Up @@ -1347,6 +1362,9 @@ or most optimal searcher."
(:language "javascript" :ext "css" :agtype "css" :rgtype "css")
(:language "dart" :ext "dart" :agtype nil :rgtype "dart")
(:language "lua" :ext "lua" :agtype "lua" :rgtype "lua")
;; the extension "m" is also used by obj-c so must use matlab-mode
;; since obj-c will win by file extension, but here for searcher types
(:language "matlab" :ext "m" :agtype "matlab" :rgtype "matlab")
(:language "nim" :ext "nim" :agtype "nim" :rgtype "nim")
(:language "nix" :ext "nix" :agtype "nix" :rgtype "nix")
(:language "org" :ext "org" :agtype nil :rgtype "org")
Expand Down Expand Up @@ -1758,17 +1776,23 @@ to keep looking for another root."
(let* ((languages (-distinct
(--map (plist-get it :language)
dumb-jump-find-rules)))
(language (or (dumb-jump-get-language-by-filename file)
(dumb-jump-get-language-from-mode))))
(language (or (dumb-jump-get-language-from-mode)
(dumb-jump-get-language-by-filename file)
(dumb-jump-get-mode-base-name))))
(if (member language languages)
language
(format ".%s file" (or (f-ext file) "")))))

(defun dumb-jump-get-mode-base-name ()
"Get the base name of the mode."
(s-replace "-mode" "" (symbol-name major-mode)))

(defun dumb-jump-get-language-from-mode ()
"Extract the language from the 'major-mode' name. Currently just everything before '-mode'."
(let ((lookup '(sh "shell" cperl "perl"))
(m (s-replace "-mode" "" (symbol-name major-mode))))
(or (plist-get lookup (intern m)) m)))
(let* ((lookup '(sh "shell" cperl "perl" matlab "matlab"))
(m (dumb-jump-get-mode-base-name))
(result (plist-get lookup (intern m))))
result))


(defun dumb-jump-get-language-by-filename (file)
Expand Down Expand Up @@ -2009,6 +2033,7 @@ current file."
(:comment "#" :language "perl")
(:comment "//" :language "php")
(:comment "#" :language "python")
(:comment "%" :language "matlab")
(:comment "#" :language "r")
(:comment "#" :language "ruby")
(:comment "#" :language "crystal")
Expand Down
2 changes: 1 addition & 1 deletion test/dumb-jump-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
(ert-deftest dumb-jump-get-lang-major-mode-test ()
(let* ((major-mode 'php)
(lang1 (dumb-jump-get-language "blah/file.install"))
(lang1b (dumb-jump-get-language-from-mode))
(lang1b (dumb-jump-get-mode-base-name))
(lang2 (dumb-jump-get-language-by-filename "/askdfjkl/somefile.js")))
(should (string= lang1 "php"))
(should (string= lang1b "php"))
Expand Down