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

Simplify codemirror ipython-mode #3577

Merged
merged 1 commit into from Jul 9, 2013
Merged

Conversation

Carreau
Copy link
Member

@Carreau Carreau commented Jul 8, 2013

make it a subset of python mode, only with configuration

diff is ugly, here is what the mode look like now

// IPython mode is just a slightly altered Python Mode with `?` beeing a extra
// single operator. Here we define `ipython` mode in the require `python`
// callback to auto-load python mode, which is more likely not the best things
// to do, but at least the simple one for now.

CodeMirror.requireMode('python',function(){

    CodeMirror.defineMode("ipython", function(conf, parserConf) {

        parserConf.singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\\?]");
        parserConf.name = 'python'
        return CodeMirror.getMode(conf, parserConf);
    }, 'python');

    CodeMirror.defineMIME("text/x-ipython", "ipython");
})

This has been only recently possible because of some changes on CodeMirror side.

make it a subset of python mode, only with configuration
@minrk
Copy link
Member

minrk commented Jul 8, 2013

Looks good to me, great cleanup!

@Carreau
Copy link
Member Author

Carreau commented Jul 8, 2013

Yeah, I'm trying to improve python-mode on CM to also have Cython.
Do you know by any chance where I could find a list of all cython keywords and token that would have to be highlighted ?

@ivanov
Copy link
Member

ivanov commented Jul 8, 2013

here's a /syntax/pyrex.vim that might help, Matthias:

" Vim syntax file
" Language: Pyrex
" Maintainer:   Marco Barisione <marco.bari@people.it>
" URL:      http://marcobari.altervista.org/pyrex_vim.html
" Last Change:  2009 Nov 09

" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
  syntax clear
elseif exists("b:current_syntax")
  finish
endif

" Read the Python syntax to start with
if version < 600
  so <sfile>:p:h/python.vim
else
  runtime! syntax/python.vim
  unlet b:current_syntax
endif

" Pyrex extentions
syn keyword pyrexStatement      cdef typedef ctypedef sizeof
syn keyword pyrexType       int long short float double char object void
syn keyword pyrexType       signed unsigned
syn keyword pyrexStructure  struct union enum
syn keyword pyrexInclude    include cimport
syn keyword pyrexAccess     public private property readonly extern
" If someome wants Python's built-ins highlighted probably he
" also wants Pyrex's built-ins highlighted
if exists("python_highlight_builtins") || exists("pyrex_highlight_builtins")
    syn keyword pyrexBuiltin    NULL
endif

" This deletes "from" from the keywords and re-adds it as a
" match with lower priority than pyrexForFrom
syn clear   pythonInclude
syn keyword pythonInclude     import
syn match   pythonInclude     "from"

" With "for[^:]*\zsfrom" VIM does not match "for" anymore, so
" I used the slower "\@<=" form
syn match   pyrexForFrom        "\(for[^:]*\)\@<=from"

" Default highlighting
if version >= 508 || !exists("did_pyrex_syntax_inits")
  if version < 508
    let did_pyrex_syntax_inits = 1
    command -nargs=+ HiLink hi link <args>
  else
    command -nargs=+ HiLink hi def link <args>
  endif
  HiLink pyrexStatement     Statement
  HiLink pyrexType      Type
  HiLink pyrexStructure     Structure
  HiLink pyrexInclude       PreCondit
  HiLink pyrexAccess        pyrexStatement
  if exists("python_highlight_builtins") || exists("pyrex_highlight_builtins")
      HiLink pyrexBuiltin   Function
  endif
  HiLink pyrexForFrom       Statement

  delcommand HiLink
endif

let b:current_syntax = "pyrex"

@Carreau
Copy link
Member Author

Carreau commented Jul 9, 2013

Thanks @ivanov, a few more keywords to add to the list. I was astonished not to find a list in the official doc.
Will merge now.

Carreau added a commit that referenced this pull request Jul 9, 2013
Simplify codemirror ipython-mode

make it a subset of python mode, only with configuration
@Carreau Carreau merged commit 2453888 into ipython:master Jul 9, 2013
@Carreau Carreau deleted the simple-mode branch July 9, 2013 09:21
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Simplify codemirror ipython-mode

make it a subset of python mode, only with configuration
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

Successfully merging this pull request may close these issues.

None yet

3 participants