Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from openmainframeproject/development
Browse files Browse the repository at this point in the history
Revision bar support, snippets for common abbreviations
  • Loading branch information
johnarwe authored Sep 14, 2017
2 parents 5e66b9a + ed165e7 commit 5536cd3
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.1.2 - New function to add BookMaster revision bars
* New `addRevisionBars` command to add :rev/:erev around current editor cursor(s), mapped to CTL-ALT-V by default, with the refid value supplied in a package setting

## 0.1.1 - Bug fix
* Toggle command throws an exception due to a publishing typo

Expand Down
5 changes: 3 additions & 2 deletions keymaps/language-zvm-gml.cson
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# - Commented out all generated "code", since this package is not supplying
# any default key bindings. Commented it out rather than deleting it
# in case default key bindings are needed in the future.
# - add addRevisionBars binding

# Keybindings require three things to be fully defined: A selector that is
# matched against the focused element, the keystroke and the command to
Expand All @@ -14,5 +15,5 @@

# For more detailed documentation see
# https://atom.io/docs/latest/behind-atom-keymaps-in-depth
#'atom-workspace':
# 'ctrl-alt-o': 'language-zvm-gml:toggle'
'atom-text-editor':
'ctrl-alt-v': 'language-zvm-gml:addRevisionBars'
51 changes: 49 additions & 2 deletions lib/language-zvm-gml.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ module.exports = LanguageZvmGml =
modalPanel: null
subscriptions: null
elementHadFocus: null
userVisiblePackageName: 'language-zvm-gml' # Used for config keys, amongst other things
debugging: false

# http://flight-manual.atom.io/behind-atom/sections/configuration-api/
# https://atom.io/docs/api/v1.19.7/Config
config:
revisionRefid:
title: "Revision bar REFID"
description: "The refid value used on the BookMaster :rev/:erev tags when running the addRevisionBars command"
type: 'string'
default: ""

activate: (state) ->
@languageZvmGmlView = new LanguageZvmGmlView(state.languageZvmGmlViewState)
Expand All @@ -17,6 +28,8 @@ module.exports = LanguageZvmGml =

# Register command that toggles this view
@subscriptions.add atom.commands.add 'atom-workspace', 'language-zvm-gml:toggle': => @toggle()
@subscriptions.add atom.commands.add 'atom-text-editor', 'language-zvm-gml:addRevisionBars': => @addRevisionBars()
console.log 'LanguageZvmGml finished activation' if @debugging

deactivate: ->
@modalPanel.destroy()
Expand All @@ -27,12 +40,46 @@ module.exports = LanguageZvmGml =
languageZvmGmlViewState: @languageZvmGmlView.serialize()

toggle: ->
console.log 'LanguageZvmGml was toggled!'

if @modalPanel.isVisible()
console.log @userVisiblePackageName + ' was toggled, visible >> invisible' if @debugging
@modalPanel.hide()
@elementHadFocus?.focus()
else
console.log @userVisiblePackageName + ' was toggled, visible << invisible' if @debugging
@modalPanel.show()
@elementHadFocus = document.activeElement
@modalPanel.getItem().focus() # Needed for clickToHide to work

# addRevisionBars:
# - Uses ...Ranges() (plural) so it handles multiple cursors.
# - Deals in markers instead of ranges (which would be less code)
# because it's inserting text, and ranges do not get adjusted for
# inserts on the fly (while markers do get adjusted).
addRevisionBars: ->
editor = atom.workspace.getActiveTextEditor()
console.log "addRevisionBars ", editor if @debugging
if editor?
selectedRanges = editor.getSelectedBufferRanges()
selectedMarkers = []
markerProperties = { "invalidate": "never"}
selectedMarkers.push( editor.markBufferRange(oneRange,markerProperties) ) for oneRange , i in selectedRanges
console.log "addRevisionBars markers ", selectedMarkers if @debugging
@addRevisionBarsToRange editor, m for m in selectedMarkers

addRevisionBarsToRange: (editor, oneMarker) ->
r = oneMarker.getBufferRange()
console.log "addRevisionBarsToRange: ", editor, oneMarker , r if @debugging
refid = atom.config.get @userVisiblePackageName+".revisionRefid"
if refid
editor.setCursorBufferPosition([r.start.row , 0])
editor.insertText(":rev refid=" + refid + ".\n")
# Update the range, whose bounds do not reflect the just-inserted text
r = oneMarker.getBufferRange()
editor.setCursorBufferPosition([r.end.row+1 , 0])
editor.insertText(":erev refid=" + refid + ".\n")
else
atom.notifications.addWarning("The revision's refid is empty. Set the value in the package's settings.",
{dismissable:true,
detail: "Open File > Settings > Packages, filter on " + @userVisiblePackageName +
", click on the Settings control for that package, scroll to its Settings section, " +
"and set it to a non-blank value."})
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "language-zvm-gml",
"main": "./lib/language-zvm-gml",
"version": "0.1.1",
"version": "0.1.2",
"description": "Syntax highlighting for z/VM SCRIPT files, containing Script and/or BookMaster tags",
"keywords": [
"language",
Expand All @@ -10,8 +10,12 @@
"syntax"
],
"activationCommands": {
"atom-workspace": "language-zvm-gml:toggle"
"atom-workspace": "language-zvm-gml:toggle",
"atom-text-editor": "language-zvm-gml:addRevisionBars"
},
"activationHooks": [
"language-zvm-gml:grammar-used"
],
"repository": "https://github.com/openmainframeproject/atompkg-language-zvm-gml",
"license": "Apache 2",
"comment": "See NOTICE.md for copyright notices",
Expand Down
13 changes: 13 additions & 0 deletions snippets/language-zvm-gml.cson
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

# - Yes, the triggers DO NOT include the leading : ... see
# https://github.com/openmainframeproject/atompkg-language-zvm-gml/issues/2
# for why that's currently A Good Thing.

'.source.GML':
#
'ordered-list':
Expand Down Expand Up @@ -37,3 +42,11 @@
'system-programmer':
'prefix': 'sysprog'
'body': "system programmer"
#
'racfvm':
'prefix': 'racfvm'
'body': "RACF/VM"
#
'smapi':
'prefix': 'smapi'
'body': "SMAPI"

0 comments on commit 5536cd3

Please sign in to comment.