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

provide an "open-at-point" function #18

Open
nico202 opened this issue Sep 3, 2018 · 4 comments
Open

provide an "open-at-point" function #18

nico202 opened this issue Sep 3, 2018 · 4 comments

Comments

@nico202
Copy link

nico202 commented Sep 3, 2018

The idea is to have a simple way to open the file or folder at point/in the current line. Something like the following but that supports variables:

(defun nx/meson-open-at-point ()
  (interactive)
  (let ((line (thing-at-point 'line 'no-properties))
	(found 'nil))
    ;; subdir -> subdir/meson.build
    (when (string-match "^subdir\s*('\\([^']+\\)')" line)
      (find-file (concat (match-string-no-properties 1 line) "/meson.build"))
      (setq found t))
      ;; include_directories -> open dir
    (when (and (not found)
	       (string-match "include_directories\s*('\\([^']+\\)')" line))
      (find-file (match-string-no-properties 1 line))
      (setq found t))
    (when (and (not found)
		(string-match "dependency\s*('\\([^']+\\)')" line))
      (message "dependencies not supported!")
      (setq found t))
    ;; string fallback
    (when (and (not found)
		(string-match "'\\(.+\\)'" line))
      (find-file (match-string-no-properties 1 line))
      (setq found t))
    ;; executable, shared_library, static_library?
    (when (not found)
      (message "Nothing found at point"))))
@wentasah
Copy link
Owner

Hi, this would definitely be useful. I only don't know how the "that support variables" could be implemented. Meson has meson introspect subcommand, but this does not seem to support queries for variables. In addition, that command needs a path to the build directory and this mode has no clue where your build directory can be. Do you have an idea how the variable support could be implemented?

@nico202
Copy link
Author

nico202 commented Nov 16, 2018

Something that feels a bit hacky is:

  • copy the meson file until current line
  • Add: message(get_variable('variable_name'))
  • run meson build /tmp/some-dir
  • parse the Message: Something output

It works with textual variables like:

test = 'a'
message('emacs-output-begin:')
message(get_variable('test'))
message(':emacs-output-end')

But I still have to look at how to print include_directories() objects

@nico202
Copy link
Author

nico202 commented Nov 16, 2018

It works with arrays

Message: emacs-output-begin:                                                                                                                                                                     
Message: ['main.cc', 'Helpers.cc', 'Structs.cc', 'audio/Audio.cc', 'video/Monitor.cc', 'video/TeensyLED.cc', 'haptics/Haptics.cc', 'geometry/Ellipse.cc']                                        
Message: :emacs-output-end

@nico202
Copy link
Author

nico202 commented Nov 16, 2018

A maybe less hacky thing to do is to write a python script that imports

from mesonbuild import mesonmain

and does the evaluation (not sure which function). The cool part about this is that probably it will work even with external dependencies, when they are resolved

edit:
indeed is possible with something like:

glfw = dependency('glfw3')
ftgl = dependency('ftgl')

message(ftgl.get_pkgconfig_variable('prefix'))
message(glfw.get_pkgconfig_variable('includedir'))

(don't know which variable is more useful. But I'd love to easily be able to jump to the include dir to know exactly what I'm using)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants