Using Emacs - 8 - Autocomplete

Out of the box, Emacs supports various types of completion.

Tab completion for filenames and commands basically work right out of the box and Emacs has built in modes like Abbrev, Hippie Expand, and Dabbrev provide a manner of completion for in buffer text.

I briefly show Dabbrev (Dynamic Abbrevs) in the video and if you're interested in the others, follow the links.

We saw ow the built in Ido mode and third party packages like Ivy, which I prefer, and Helm make for better completions on functions, filenames, and the like and Emacs also has third party packages for in buffer completion.

The two main contenders are auto-complete Mode and company Mode. I use auto-complete, others swear by company. The video shows the basics of auto-complete mode but check both out and decide for yourself.

If you feel strongly about one or the other, please share in the comments.

Here's a basic configuration:

(use-package auto-complete
  :ensure t
  :init
  (progn
    (ac-config-default)
    (global-auto-complete-mode t)
    ))

We'll modify this as move along in the series.

Here's the video:

Relevant links:

Using Emacs - 7- Navigation with Avy

Here's a really cool navigation method that I've been meaning to use more. Avy is a replacement for ace-jump mode which is an implementation of easymotion, a vim plugin.

It's pretty cool and lets you quickly navigate to any spot on the screen.

After triggering avy, or more specifically the avy-goto-char function, emacs prompts you for a single character. When you type it, all instances of the character that start out words change to a highlighted letter. Type the highlighted letter and you jump to that location.

The avy package comes with a bunch of options including a 2 character search variant, a timed variant which drops into search, and more.

The Avy home page has all the details.

Here's the configuration I'm using:

(use-package avy
  :ensure t
  :bind ("M-s" . avy-goto-char))

You can check the avy home page for their recommended configuration which you get by configuring this way instead:

(use-package avy
  :ensure t
  :config
  (avy-setup-default))

Relevant links:

Lesson plans - scripts to springboards

I spent last Saturday up at the Microsoft offices in Times Square observing a TEALS training session. My fried Nathaniel Granor, Teals Regional Manager in the east has invited me a number of times and this time I was able to make it.

If you don't know, TEALS is a program that takes volunteers in the tech industry and places them in classrooms. Unlike other programs, the TEALS volunteers work with the teachers while the kids learn some CS. The idea is that the teacher will learn about CS from the volunteer and the volunteer will learn something about teaching.

It's not the same as having a strong, knowledgeable CS teacher in the classroom but until we get there, TEALS is doing great work giving kids something that they need and otherwise wouldn't get.

At one point, Nathaniel started to talk to the volunteers about lesson plans emphasizing the fact that TEALS would provide all the lesson materials and the plans so these new to teaching tech volunteers wouldn't have to make curricular decisions.

The lesson plan form was pretty traditional and pretty formulaic:

  • warm up
  • hook
  • instruction
  • practice
  • Assessment

Very similar to what I was shown back in the day during my two day "teaching boot camp" that kicked off my career 1 and very appropriate as an effective and efficient way to prepare these volunteers for their first days.

This got me thinking about my lesson planning over the years.

When I started, I was teaching math but I wasn't really a math guy - I was CS all the way. I had to remember the math from high school, learn the new topics, and figure out how to teach it.

I had a very supportive department but they were busy with their own classes and this was pre internet. Fortunately, the NYC DOE published lesson plan books. They were basically bound volumes of xerox copies of hand written and typed lesson plans provided by experienced teachers.

I spent many hours copying them, studying them, and then later tweaking them.

They were a life saver back then. How was the teaching? OK. Not great. I got the material to the kids but I was nothing special. This is where I started to form my bias against the scripted teaching that's being pushed down today.

As I developed my chops, I started to design my own experiences for my classes and things improved. By the time I was done teaching math - maybe 4 years in, I was just scratching the surface of being a math teacher.

One year in, I started teaching CS along with math at Seward Park. When I was bumped to Stuy, I went back to math for a year and a half and then it was all CS all the time.

For CS, we didn't have lesson plan books so I had to craft everything from scratch. It was a lot of work but the results were much better.

At first, I would actually write out lesson plans a la math lesson plans. A "do now," "instructional objectives," "applications," "Homework," etc. The only thing I never formally wrote out was a "medial summary."

Over time, my lessons got better but my lesson plans looked worse and worse.

There were times a lesson plan might look something like this:

plan.jpg

OK, not exactly but as I developed at my craft, I didn't need a laid out script to follow line for line rather, just a set of little reminders and maybe some printed out code. If we were going to develop a complicated algorithm or derivation, though, I would still write out all the steps.

This doesn't mean that as my career progressed I planned any less. It might appear that I'm winging it but even if little to nothing is written down, there is a plan and there's always a lot of pre work before class begins.

Now, to bring this back to TEALS.

It's interesting how what's good in one context is not so much in another.

What TEALS is doing is great - they've got to get a lot of technologists in to classrooms quickly but once there, they'll be with real, hopefully experienced teachers. What they're doing gets them ready to go. It's a starting point, not an end.

On the other hand, when I see scripted curriculum being sold as the special sauce, be it in CS teacher "training," Teach for America summer prep or in the name of charter school uniformity, I run the other way.

Let's prepare curricular materials for important programs like TEALS and for beginning teachers just starting out but let's not confuse a scripted lesson that can be delivered by one and all to be anything close to the work of a master educator and craftsman.

Footnotes:

1

full disclosure: I came in to teaching with zero education credentials and took the minimum number of ed classes for my license after I started.

Better Comments or tooling as a time sink

The other day my friend and fellow CS Ed Blogger Alfred Thompson wrote about Better Comments, an extension for visual studio that displays comments that are marked up with special characters in order to highlight them. Here's a screenshot:

ClassificationC.png

So, the first thing I though was "I bet emacs could do that pretty easily" and down the rabbit hole I went.

I had to figure out something about how emacs themes and font-locking (emacs for syntax highlighting) works and of course spent far too much time learning about Emacs, my favored tool, rather than getting actual work done, but I came up with this:

(make-face 'font-lock-comment-important)
(set-face-foreground 'font-lock-comment-important "#00ff00")

(make-face 'font-lock-comment-todo)
(set-face-foreground 'font-lock-comment-todo "#ff0000")

(make-face 'font-lock-comment-strike)
(set-face-attribute 'font-lock-comment-strike
		    nil :strike-through t)

(defun add-custom-keyw()
  "adds a few special keywords"
  (font-lock-add-keywords 
   nil
   '(("cx \\(.+\\)" 1 'font-lock-comment-strike prepend)
     ("ct \\(.+\\)" 1 'font-lock-comment-todo prepend)
     ("ci \\(.+\\)" 1 'font-lock-comment-important prepend)
     )
   ))
(add-hook 'python-mode-hook 'add-custom-keyw)
(add-hook 'js2-mode-hook 'add-custom-keyw)
(add-hook 'js-mode-hook 'add-custom-keyw)

It's a hack but it does indeed work. In action, it looks something like this:

Truth be told, it really colors anything following cx, ct, or ci, not just in comments – I have to look a bit more into how emacs handles comments to figure that one out.

In any event, even though I spent too much time doing this, it's nice to know I'm working in a tool in which I can.

UPDATE: Thanks to user ncsuwolf on /r/emacs on reddit, here's a fully working, more properly done solution:

(defface font-lock-comment-strike
  '((t (:strike-through t)))
  "For strike-through comments")

(defface font-lock-comment-important
  '((t (:foreground "#00ff00")))
  "For important")
(defface font-lock-comment-todo
  '((t (:foreground "#ff0000"))
		"For todo comments")
(defun add-custom-keyw()
		"adds a few special keywords"
		(font-lock-add-keywords
		 nil
		 '(("\\s<+x[[:space:]]*\\(.*?\\)[[:space:]]*\\s>" 1 'font-lock-comment-strike prepend)
			 ("\\s<+t[[:space:]]*\\(.*?\\)[[:space:]]*\\s>" 1 'font-lock-comment-todo prepend)
			 ("\\s<+i[[:space:]]*\\(.*?\\)[[:space:]]*\\s>" 1 'font-lock-comment-important prepend))))

	(add-hook 'prog-mode-hook #'add-custom-keyw)

Using Emacs - 6 - Searching a Swiper

This video is all about using incremental search to navigate through your emacs buffers.

You can use the default incremental searchb, bound to C-s for isearch-forward C-r to search backwards (reverse).

They work really well as is but I prefer using Swiper. The video demos both and the Swiper home page has loads of details.

Part of the Swiper package includes ivy and counsel which I use instead of ido.

The video also mentions lorem-ipsum mode for generating text quickly and describe-mode in the help system.

Here's the code we added for swiper:

;; it looks like counsel is a requirement for swiper
(use-package counsel
  :ensure t
  )

(use-package swiper
  :ensure try
  :config
  (progn
    (ivy-mode 1)
    (setq ivy-use-virtual-buffers t)
    (global-set-key "\C-s" 'swiper)
    (global-set-key (kbd "C-c C-r") 'ivy-resume)
    (global-set-key (kbd "<f6>") 'ivy-resume)
    (global-set-key (kbd "M-x") 'counsel-M-x)
    (global-set-key (kbd "C-x C-f") 'counsel-find-file)
    (global-set-key (kbd "<f1> f") 'counsel-describe-function)
    (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
    (global-set-key (kbd "<f1> l") 'counsel-load-library)
    (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
    (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
    (global-set-key (kbd "C-c g") 'counsel-git)
    (global-set-key (kbd "C-c j") 'counsel-git-grep)
    (global-set-key (kbd "C-c k") 'counsel-ag)
    (global-set-key (kbd "C-x l") 'counsel-locate)
    (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
    (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
    ))

and we commented out the ido stuff:

;; using swiper so ido no longer needed
;;(setq ido-enable-flex-matching t)
;;(setq ido-everywhere t)
;;(ido-mode 1)

If you want to see a nice video specifically on swiper by the author, here it is:

Relevant links:

Robots platforms and practicalities

I received an email from a friend the other day asking me about a particular robotics platform she recently saw.

I've played with robotics on and off over the years ranging from building them from (not using) scratch using Atmel chips and programming them in assembly to using Arduino based platforms to using pre-built robot platforms. They're really cool and since they interact with the real world you can do all sorts of interesting and motivational things with students.

I've done these on my own as a hobbyist and also with students either individually or in small groups, but never as part of a class I had been teaching.

Why not?

The biggest reason is that the classes I've taught are already so packed full of CS goodness that we can't even get everything done that's theoretically on the syllabi.

The other has to do with practical concerns.

Equipment costs - Let's say we can get our platform at $100 a pop. I just can't see a public school with 34 kids in a class getting one per student or one for every two.

So, what's the robot to student ratio and how much actual access do the kids get? If they're designing building, do they all get to design and build? Same question with coding and operating.

Then there's space – if we're talking about a mobile platform as opposed to something that sits on the desk and is near stationary, we have a problem. The classrooms I've taught in can barely hold the students.

There are also issues with breakage, loss, theft and long term maintainability - will we be able to or even want to fill in with compatible units in a few years as needed or will we have to reboot the program from scratch.

All that to deal with before we even get to the fun of teaching and learning.

I'm really curious about the experiences of those of you who do teach using robots and similar platforms.

If you are such a teacher, could you please fill out this form or leave a comment for anything that the form doesn't cover?

Using Emacs - 5 - Windows

Sorry for the delay in getting this next video / post up. I spent the last part of last week at The Personal Democracy Forum 2016 which is really an exceptional conference.

I posted a bit about it in my last post and plan to write some more on it, but for now, more Emacs.

This video concerns using windows. By using buffers and windows and the basics you got from the tutorial, you shouldn't have to ever leave emacs.

From here, we'll be able to start going over effective Emacs and then using it for things like development or document creation.

Some of the key window bindings:

key what it does
C-x 2 split-window-below (vertically)
C-x 3 split-window-right (horizontally)
C-x 0 delete-window (this one)
C-x 1 delete-other-windows
C-x o other-window (moves foxus to the next window

You also have frames which use C-x 5 as the prefix, so C-x 5 2 creats a new frame and C-x 5 1 closes the other frames.

Remember, you can always use the help system, in particular C-x k to describe a key and C-x f to describe a function.

C-x o can be a little clunky so some people like to use windmove which lets you move between windows by holding the shift key and with the arrows. To set that up, you can add this to your init.el

(windmove-default-keybindings)

I prefer using ace-window mode which still uses C-x o:

; add this to init.el
(use-package ace-window
  :ensure t
  :init
  (progn
    (global-set-key [remap other-window] 'ace-window)
    (custom-set-faces
     '(aw-leading-char-face
       ((t (:inherit ace-jump-face-foreground :height 3.0))))) 
    ))

The other mode I mention in the video is winner mode:

(winner-mode 1)

Which will allow you to use C-c left or right to move through past window configurations.

Relevant links:

PDF 2016 - How we lost the open web

I spent the last couple of days attending Personal Democracy Forum 2016, described on their landing site as:

The world’s leading conference exploring and analyzing technology's impact on politics, government, and society.

That's the reason why I haven't posted my latest Emacs video.

PDF is a great conference and raised a huge number of important issues. I'll probably blog about a few over the next few weeks.

One topic that I've already lamented about has been the way we as a society are allowing so much information to be silo-ed in platforms like Facebook.

I use Facebook as much as the next guy but it always irks me when I see a CS Education post followed by rich discussion hidden within Facebook's walls and not available for discovery to the outside world and the future.

I generally don't get a lot of comments on my posts, but when I do, more appear in the Facebook link to my post rather than publicly on the post itself.

At the conference, we watched a video by Hossein Derakhshan which talked about the direction the web is moving in and the red flags it should raise with all of us. He echoed my concerns and beyond but in a much more eloquent way.

I'm urging you to take the less than ten minutes to watch this video. I know school's winding down for all of us but for those of you who are teachers out there - share this with your students. I'm sure a rich discussion will follow.

Navajo Math Circles

Yesterday, I saw the New York Premiere of Navajo Math Circles, a documentary on a Math Circle put in place to support and enrich the currently under-served community in the Navajo educational system.

At their core, Math Circles are math outreach and enrichment programs. I'm most familiar with the New York Math Circle. I'm friends with many of their teachers and organizers and my son took part in their summer program for a couple of years.

Over in the southwest, these Math Circles have been bringing together students, frequently across great distances each day to explore problem solving and creativity through mathematics.

As someone who's worked hard to bring educational opportunities to the have nots, I love the program. Some of the highlights include the kids working on open ended problems, focusing on process and techniques more than specific results, working both collaboratively but also developing self sufficiency, and more. I also love the fact that they've started teacher math circles to help to bring some of that math circle magic to the everyday classroom.

I enjoyed the film and recommend you check it out to see what's possible and I want to share my two big takeaways.

First, early on in the film, one of the people running the program talked about developing a math enrichment program through and with Navajo traditions and culture. This is HUGE and I feel it's something we're losing. America is so diverse from coast to coast and here in New York City you can see radically different ways of life living right across the street from each other. Everyone pays lip service to "making the work interesting and relevant to the student" but few people walk the walk. These folk do.

Second, I left the documentary with a sour taste in my mouth. Not because of the program but because the Navajo Math Circle project and projects like it are scraping together what little resources they can to try to do what the school systems should be doing to begin with.

As we move to scripted lessons, national standards, curricula dictated or at least influenced by large private concerns and standardized tests, our schools are moving further and further away from community and local culture.

In the documentary, one student pointed out that in math class, they have to use the textbook. They learn the process and then have to solve the problems. In Math Circle, there are no textbooks.

Afterwards, the students in from the Math Circle did some Q&A. I asked them to elaborate - what's the difference between there Math Circle experiences and their in school ones. I got:

Math Circle is fun!!!!

I think that says it all.

I know many great teachers who try to bring culture and community to their classes. One of my son's best teachers, Paula Rogovin did it all the time. Many of my friends and colleagues try to do so as well but the powers that be make it harder and harder.

Until we win back public education it's important to support programs like Math Circles (and, if I do say so myself, programs like our own CSTUY) and it's also critical that we work to try to bring community and culture to our regular classes.

Using Emacs - 4 - Buffers

Now that we're past the intro material, we'll start looking at emacs features one at a time. This will let you focus on using the one feature we're covering, fit it into your work flow, and really get comfortable with it.

This time we'll dive into using Emacs effectively with buffers.

Watch the video and then make a real effort to use buffers over the next few emacs sessions. Before you know it, they'll be a natural part of your work flow.

The idea of incrementally learning a tool this way seems to be called developing micro-habits and I first read about the idea from Sacha Chua who is an amazing member of the emacs community.

When seeing beginners, I'll frequently observe this work flow:

  • Open a terminal
  • Load emacs on a file
  • Edit the file
  • Save and quit emacs
  • Try to compile and run the program (since usually this is in a programming class)
  • repeat

If the beginner needs to see multiple files at once, they fire up multiple separate emacs.

All of this causes me physical pain.

In emacs, your editor can load several buffers at once, each associated with a separate file. You can quickly switch between them, search across them, and more. The video will get you started.

The video also mentions ido mode. To set up ido mode, add the following code to your init.el:

(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode 1)

And here's a great little write up on it by Mickey Petersen:

https://www.masteringemacs.org/article/introduction-to-ido-mode

As I mentioned in the video, I actually use another mode for completions (swiper), which I'll cover in a future video and another popular option is helm which we'll also cover.

For buffers, the keys to remember are:

Key Command
C-x b switch-buffer
C-x C-b list-buffers

To use ibuffer, which is more powerful than list-buffers you can add either:

(defalias 'list-buffers 'ibuffer) ; make ibuffer default

Or if you want to open ibuffer in another Window:

(defalias 'list-buffers 'ibuffer-other-window) ; make ibuffer default

Here are a couple of useful links on ibuffer and buffer switching:

Finally, if you like a tab bar, you can add the following to your init.el:

(use-package tabbar
  :ensure t
  :config (tabbar-mode 1)
)

There's also a package tabbar-ruler which is supposed to make the tabbar look nicer but since I don't use the tabbar at all, I haven't checked it out.

Hope this gets you using emacs more effectively.

Stay tuned for our next video on window management.

Relevant links:


Enter your email address:

Delivered by FeedBurner

Google Analytics Alternative