Group Abstract Group Abstract

Message Boards Message Boards

Display the line number in a mathematica package?

Posted 7 years ago

for example ,

BeginPackage[ "Package`"]

  MainFunction::usage = 
    "MainFunction[ x] computes a simple function."

  Begin[ "Private`"]

  MainFunction[ x_] :=
    Module[ {y},
      y = x^2;
      y + 1
    ]

  End[]

  EndPackage[]

i don't know how to display the line number in a mathematica's .m file. Thank you in advance!

POSTED BY: zhu xiaoming
10 Replies
Posted 6 years ago

Nice to meet you. I have a question about wolfram workbench. I want to talk to you in private. My email address is 1262043385@qq.com

POSTED BY: zhu xiaoming

I feel quite comfortable to work with Mathematica package with Visual Studio code. There are several add-ons in vs code to show syntax highlighting and function name detection.

POSTED BY: Shenghui Yang
Posted 7 years ago

I have never required line numbers while programming Mathematica EXCEPT in one particular important case: when writing a package in a notebook that then gets converted to a '.m' file (which is plaintext). If one makes some sort of syntax error like an extra comma or such, then when one goes to load the package there will be an error message about the syntax error, and the package will fail to load. Unfortunately, however, there is no mention of where in your package the error might actually be. If one has a large package then this clearly becomes an issue.

There is a workaround, however. Parallel kernels do have some magic ability to tell one the exact line number where syntax errors occur. If one does e.g.:

ParallelEvaluate[Needs["myPackage.m"]]

then each and every one of the kernels will return a message with the line number of your error.

It would, of course, be nice if this were just the default behavior without having to do this workaround.

B

POSTED BY: Bernard Gress
Posted 7 years ago

A Mathematica package file, .m or .wl, can easily be opened in a standard text editor. Which can display the line numbers. The picture below is from using UltraEdit.

enter image description here

POSTED BY: Hans Milton
Posted 7 years ago

A Mathematica package file, .m or .wl, can easily be opened in a text editor. Which can display the line numbers. The picture below is from using UltraEdit.

enter image description here

POSTED BY: Hans Milton

There are a host of advantages to using an integrated development environment when working with packages, showing line number is just one of them. If the notebook satisfies all of your needs then that's great.

But many people choose to write their Wolfram Language code in another editor, and have written great plugins for those editors. See the list here: https://arnoudbuzing.github.io/wolfram/editors.html

POSTED BY: Jason Biggs
Anonymous User
Anonymous User
Posted 7 years ago
POSTED BY: Anonymous User
Posted 7 years ago

I see?thank you very much!

POSTED BY: zhu xiaoming

I rarely edit a Mathematica package file using Mathematica, but instead edit them in Eclipse with the workbench plugin. See here for more information about using Eclipse.

Showing line numbers by default in Eclipse is a simple setting to change.

POSTED BY: Jason Biggs
Anonymous User
Anonymous User
Posted 7 years ago
POSTED BY: Anonymous User
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard