You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/03-hacking-atom/sections/03-modify-buffer.asc
+20-21Lines changed: 20 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -3,13 +3,12 @@
3
3
Now that we have our first package written, let's go through examples of other types of packages we can make. This section will guide you though creating a simple command that replaces the selected text with https://en.wikipedia.org/wiki/ASCII_art[ascii art]. When you run our new command with the word "cool" selected, it will be replaced with:
4
4
5
5
```
6
-
___
7
-
/\_ \
8
-
______ ___\//\ \
9
-
/'___\ / __`\ / __`\\ \ \
10
-
/\ \__//\ \L\ \/\ \L\ \\_\ \_
11
-
\ \____\ \____/\ \____//\____\
12
-
\/____/\/___/ \/___/ \/____/
6
+
o888
7
+
ooooooo ooooooo ooooooo 888
8
+
888 888 888 888 888 888 888
9
+
888 888 888 888 888 888
10
+
88ooo888 88ooo88 88ooo88 o888o
11
+
13
12
```
14
13
15
14
This should demonstrate how to do basic text manipulation in the current text buffer and how to deal with selections.
@@ -20,23 +19,22 @@ The final package can be viewed at https://github.com/atom/ascii-art.
20
19
21
20
To begin, press `cmd-shift-P` to bring up the https://github.com/atom/command-palette[Command
22
21
Palette]. Type "generate package" and
23
-
select the "Package Generator: Generate Package" command, just as we did in <<_generate_package>>.
22
+
select the "Package Generator: Generate Package" command, just as we did in <<_generate_package>>. Enter `ascii-art` as the name of the package.
24
23
25
-
Now let's edit the package files to make our ASCII Art package do something interesting. Since this package doesn't need any UI, we can remove all view-related code so go ahead and delete `ascii-art-view.coffee`.
24
+
Now let's edit the package files to make our ASCII Art package do something interesting. Since this package doesn't need any UI, we can remove all view-related code so go ahead and delete `lib/ascii-art-view.coffee`, `spec/ascii-art-view-spec.coffee`, and `styles/`.
26
25
27
26
Next, open up `lib/ascii-art.coffee` and remove all view code, so it looks like this:
@@ -63,17 +61,19 @@ Next we insert a string into the current text editor with the https://atom.io/do
63
61
64
62
===== Reload the Package
65
63
66
-
Before we can trigger `ascii-art:convert`, we need to load the latest code for our package by reloading the window. Run the command `window:reload` from the command palette or by pressing `ctrl-alt-cmd-l`.
64
+
Before we can trigger `ascii-art:convert`, we need to load the latest code for our package by reloading the window. Run the command "Window: Reload" from the command palette or by pressing `ctrl-alt-cmd-l`.
67
65
68
66
===== Trigger the Command
69
67
70
-
Now open the command panel and search for the `ascii-art:convert` command. But it's not there! To fix this, open _package.json_ and find the property called `activationCommands`. Activation Events speed up load time by allowing Atom to delay a package's activation until it's needed. So remove the existing command and add `ascii-art:convert` to the `activationCommands` array:
68
+
Now open the command panel and search for the "Ascii Art: Convert" command. But it's not there! To fix this, open _package.json_ and find the property called `activationCommands`. Activation commands speed up load time by allowing Atom to delay a package's activation until it's needed. So remove the existing command and use `ascii-art:convert` in `activationCommands`:
71
69
72
70
```json
73
-
"activationCommands": ["ascii-art:convert"],
71
+
"activationCommands": {
72
+
"atom-workspace": "ascii-art:convert"
73
+
}
74
74
```
75
75
76
-
First, reload the window by running the command `window:reload`. Now when you run the `ascii-art:convert` command it will output 'Hello, World!'
76
+
First, reload the window by running the command "Window: Reload" from the command palette. Now when you run the "Ascii Art: Convert" command it will output 'Hello, World!'
77
77
78
78
===== Add a Key Binding
79
79
@@ -94,12 +94,11 @@ Now we need to convert the selected text to ASCII art. To do this we will use th
94
94
95
95
```json
96
96
"dependencies": {
97
-
"figlet": "1.0.8"
97
+
"figlet": "1.0.8"
98
98
}
99
99
```
100
100
101
-
After saving the file, run the command 'update-package-dependencies:update' from
102
-
the Command Palette. This will install the package's node module dependencies, only figlet in this case. You will need to run 'update-package-dependencies:update' whenever you update the dependencies field in your _package.json_ file.
101
+
After saving the file, run the command "Update Package Dependencies: Update" from the Command Palette. This will install the package's node module dependencies, only figlet in this case. You will need to run "Update Package Dependencies: Update" whenever you update the dependencies field in your _package.json_ file.
103
102
104
103
If for some reason this doesn't work, you'll see a message saying ``Failed to update package dependencies'' and you will find a new `npm-debug.log` file in your directory. That file should give you some idea as to what went wrong.
0 commit comments