Skip to content

Commit 4943f19

Browse files
committed
Now underscore-plus and underscore is not required on startup
1 parent d7d5c9d commit 4943f19

File tree

8 files changed

+32
-49
lines changed

8 files changed

+32
-49
lines changed

lib/base.coffee

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
_ = require 'underscore-plus'
1+
# To avoid loading underscore-plus and depending underscore on startup
2+
__plus = null
3+
_plus = ->
4+
__plus ?= require 'underscore-plus'
5+
26
Delegato = require 'delegato'
37
settings = require './settings'
48

@@ -20,7 +24,7 @@ loadVmpOperationFile = (filename) ->
2024
VMP_LOADED_FILES.push(filename)
2125
loaded
2226

23-
{OperationAbortedError} = require './errors'
27+
OperationAbortedError = null
2428

2529
vimStateMethods = [
2630
"onDidChangeSearch"
@@ -64,7 +68,7 @@ class Base
6468
constructor: (@vimState, properties=null) ->
6569
{@editor, @editorElement, @globalState, @swrap} = @vimState
6670
@name = @constructor.name
67-
_.extend(this, properties) if properties?
71+
Object.assign(this, properties) if properties?
6872

6973
# To override
7074
initialize: ->
@@ -92,6 +96,7 @@ class Base
9296
@operator? and not @operator.instanceof('Select')
9397

9498
abort: ->
99+
OperationAbortedError ?= require './errors'
95100
throw new OperationAbortedError('aborted')
96101

97102
# Count
@@ -250,6 +255,7 @@ class Base
250255
# -------------------------
251256
@writeCommandTableOnDisk: ->
252257
commandTable = @generateCommandTableByEagerLoad()
258+
_ = _plus()
253259
if _.isEqual(@commandTable, commandTable)
254260
atom.notifications.addInfo("No change commandTable", dismissable: true)
255261
return
@@ -272,7 +278,7 @@ class Base
272278
'./motion', './motion-search', './text-object', './misc-command'
273279
]
274280
filesToLoad.forEach(loadVmpOperationFile)
275-
281+
_ = _plus()
276282
klasses = _.values(@getClassRegistry())
277283
klassesGroupedByFile = _.groupBy(klasses, (klass) -> klass.VMP_LOADING_FILE)
278284

@@ -326,10 +332,10 @@ class Base
326332

327333
@commandPrefix: 'vim-mode-plus'
328334
@getCommandName: ->
329-
@commandPrefix + ':' + _.dasherize(@name)
335+
@commandPrefix + ':' + _plus().dasherize(@name)
330336

331337
@getCommandNameWithoutPrefix: ->
332-
_.dasherize(@name)
338+
_plus().dasherize(@name)
333339

334340
@commandScope: 'atom-text-editor'
335341
@getCommandScope: ->
@@ -352,7 +358,7 @@ class Base
352358
@registerCommandFromSpec: (name, spec) ->
353359
{commandScope, commandPrefix, commandName, getClass} = spec
354360
commandScope ?= 'atom-text-editor'
355-
commandName ?= (commandPrefix ? 'vim-mode-plus') + ':' + _.dasherize(name)
361+
commandName ?= (commandPrefix ? 'vim-mode-plus') + ':' + _plus().dasherize(name)
356362
atom.commands.add commandScope, commandName, (event) ->
357363
vimState = getEditorState(@getModel()) ? getEditorState(atom.workspace.getActiveTextEditor())
358364
if vimState? # Possibly undefined See #85
@@ -365,6 +371,7 @@ class Base
365371
# For demo-mode pkg integration
366372
@operationKind: null
367373
@getKindForCommandName: (command) ->
374+
_ = _plus()
368375
name = _.capitalize(_.camelize(command))
369376
if name of classRegistry
370377
classRegistry[name].operationKind

lib/errors.coffee

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
class VimModePlusError extends Error
1+
module.exports =
2+
class OperationAbortedError extends Error
23
constructor: ({@message}) ->
34
@name = @constructor.name
4-
5-
class OperationAbortedError extends VimModePlusError
6-
7-
module.exports = {
8-
OperationAbortedError
9-
}

lib/main.coffee

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
_ = require 'underscore-plus'
2-
31
{Disposable, Emitter, CompositeDisposable} = require 'atom'
42

53
Base = require './base'
@@ -78,23 +76,8 @@ module.exports =
7876
globalState.set('highlightSearchPattern', null)
7977

8078
@subscribe(settings.observeConditionalKeymaps()...)
81-
# @reportRequireCache(excludeNodModules: true)
82-
83-
reportRequireCache: ({focus, excludeNodModules}) ->
84-
{inspect} = require 'util'
85-
path = require 'path'
86-
packPath = atom.packages.getLoadedPackage("vim-mode-plus").path
87-
cachedPaths = Object.keys(require.cache)
88-
.filter (p) -> p.startsWith(packPath + path.sep)
89-
.map (p) -> p.replace(packPath, '')
90-
91-
for cachedPath in cachedPaths
92-
if excludeNodModules and cachedPath.search(/node_modules/) >= 0
93-
continue
94-
if focus and cachedPath.search(///#{focus}///) >= 0
95-
cachedPath = '*' + cachedPath
96-
97-
console.log cachedPath
79+
# developer?.reportRequireCache(excludeNodModules: true)
80+
developer?.reportRequireCache(excludeNodModules: false)
9881

9982
observeVimMode: (fn) ->
10083
fn() if atom.packages.isPackageActive('vim-mode')

lib/mode-manager.coffee

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
_ = require 'underscore-plus'
21
{Emitter, Range, CompositeDisposable, Disposable} = require 'atom'
32
moveCursorLeft = null
43

lib/operation-stack.coffee

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{Disposable, CompositeDisposable} = require 'atom'
22
Base = require './base'
3-
{OperationAbortedError} = require './errors'
4-
[Select, MoveToRelativeLine] = []
3+
4+
[OperationAbortedError, Select, MoveToRelativeLine] = []
55

66
# opration life in operationStack
77
# 1. run
@@ -125,6 +125,7 @@ class OperationStack
125125

126126
handleError: (error) ->
127127
@vimState.reset()
128+
OperationAbortedError ?= require './errors'
128129
unless error instanceof OperationAbortedError
129130
throw error
130131

lib/settings.coffee

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ inferType = (value) ->
1010
class Settings
1111
deprecatedParams: [
1212
'showCursorInVisualMode'
13-
'showCursorInVisualMode2'
1413
]
1514
notifyDeprecatedParams: ->
1615
deprecatedParams = @deprecatedParams.filter((param) => @has(param))

lib/status-bar-manager.coffee

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
_ = require 'underscore-plus'
21
settings = require './settings'
32

43
createDiv = ({id, classList}) ->
@@ -7,6 +6,15 @@ createDiv = ({id, classList}) ->
76
div.classList.add(classList...) if classList?
87
div
98

9+
LongModeStringTable =
10+
'normal': "Normal"
11+
'operator-pending': "Operator Pending"
12+
'visual.characterwise': "Visual Characterwise"
13+
'visual.blockwise': "Visual Blockwise"
14+
'visual.linewise': "Visual Linewise"
15+
'insert': "Insert"
16+
'insert.replace': "Insert Replace"
17+
1018
module.exports =
1119
class StatusBarManager
1220
prefix: 'status-bar-vim-mode-plus'
@@ -22,17 +30,9 @@ class StatusBarManager
2230
@element.textContent =
2331
switch settings.get('statusBarModeStringStyle')
2432
when 'short'
25-
@getShortModeString(mode, submode)
33+
(mode[0] + (if submode? then submode[0] else '')).toUpperCase()
2634
when 'long'
27-
@getLongModeString(mode, submode)
28-
29-
getShortModeString: (mode, submode) ->
30-
(mode[0] + (if submode? then submode[0] else '')).toUpperCase()
31-
32-
getLongModeString: (mode, submode) ->
33-
modeString = _.humanizeEventName(mode)
34-
modeString += " " + _.humanizeEventName(submode) if submode?
35-
modeString
35+
LongModeStringTable[mode + (if submode? then '.' + submode else '')]
3636

3737
attach: ->
3838
@tile = @statusBar.addRightTile(item: @container, priority: 20)

lib/utils.coffee

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,4 +1016,3 @@ module.exports = {
10161016
rangeContainsPointWithEndExclusive
10171017
traverseTextFromPoint
10181018
}
1019-
console.log "loaded", __filename

0 commit comments

Comments
 (0)