RSS

Category Archives: Emacs

Emacs ile ilgili her şey…

HOW-TO: Poor Man’s Quiz Scorer in Emacs Lisp


Sometimes it’s about small data.

Recently I’ve been studying a topic using a book, and at the end of each chapter there are quizzes of 20-25 questions. My method was to open a text buffer in Emacs, and vertically note down the question number, my answers, and after finishing this, go to the correct answer list, and mark correct answers with Y, and wrong ones with N:

Y 1- A,B,C
Y 2- C
N 3- D
N 4- C
Y 5- A
Y 6- B,C,D
Y 7- B

That was all fine, but I found myself counting the number of correct answers, and calculate my score in terms of percentage manually. I could of course quickly run the `M-x count-matches` (or `how-many`) to see how many correct / wrong answers I had, but doing this more than a few tests seemed to become tedious. Therefore, Emacs Lisp to the rescue!

With this simple Emacs Lisp function, assigned to F12 function key, I can now simply hit F12 and see my score percentage in Emacs:

“Your test score percentage: 71.42857142857143”

There are of course alternative methods to solve this straightforward problem, e.g. you can run some shell scripts on your Emacs (or VIM) buffer, or on a simple text file. But I like this solution being self-contained in Emacs, as well as the fact that it’ll continue to run as intended 30 years from now, in a newer Emacs version probably. This, and the fact that, my preferred tool for dealing with textual data gives me the flexibility to program it any way I want. It might have its drawbacks, it might be showing its age in its architecture, there are newer, shiny tools, there are specialized IDEs for various programming languages I use, but all of these notwithstanding, I still like to think it’s a beautiful thing that an editor released when I was born, that helped me with many tasks for decades, will still be with me for decades to come.

 
Leave a comment

Posted by on February 26, 2017 in Emacs, Programlama

 

Tags: ,

Turkish Mode for Emacs is now available as a package via MELPA


Turkish Mode for Emacs, developed by Deniz Yüret, is now available as a package via MELPA. This is for people trying to type Turkish documents on a U.S. keyboard using Emacs. The program provides a `turkish-mode` in which the correct Turkish accents are added to the ASCII version of the last word typed each time the user hits space. If you are using a recent stable version of Emacs that lets you use the Emacs package manager, and you’ve added MELPA as a repository, installing it is as easy as running:

M-x package-install turkish

and then putting the following line in your init file:

(require 'turkish)

Once you have done that, in any Emacs session you can toggle the Turkish mode

M-x turkish-mode

The same program has been converted to many different languages and available on many platforms such as a Python package, a Java package, a Perl CPAN package, an Ubuntu PPA package, a web application,  a Chrome plug-in, a Firefox add-on, and a Safari add-on.

 
Leave a comment

Posted by on March 29, 2016 in Emacs, Programlama

 

Tags:

How to edit remote files within Emacs when a program automatically runs after you SSH


If you are used to TRAMP functionality of Emacs to edit remote files without leaving the comfort of your beloved editor on your host machine, you do your best to keep it working even when different conditions arise. In my case, I’ve been recently working with virtual machines at work and the product that I’m working on is configured to run some program automatically right after I log into the machine via SSH. This prevents TRAMP functioning correctly with its default settings, because instead of receiving the shell prompt immediately, it receives from the machine the final line of the program that automatically runs and expects the user enter some response:

    ... some text menu options ...
    ...
    Please make a selection >>

Above that line, the text menu says that the user should enter 0 to exit the program or some other menu option to continue. Therefore, I had to find a way to tell Emacs that it had to send a 0 after it connects to the machine. The high-quality TRAMP manual was immediately helpful by providing a relevant example and I came up with the following: Read the rest of this entry »

 
2 Comments

Posted by on November 30, 2015 in Emacs, Lisp, Programlama

 

Tags: , , ,

How to detect Friday the 13th with full moon using Emacs


nrAlmost 21 years ago, in 1994, I bought the brand new edition of Numerical Recipes in C: The Art of Scientific Computing. As an engineering and mathematics student who was much into programming, I still remember my excitement then, as well as the bright red hard-cover.

The first algorithm presented in the book (and its implementation in C programming language) was about calculating the dates that were Friday the 13th and had full moon. Now that I’m approaching the 21st anniversary of that day, I wanted to share a similar program to detect if the current date is Friday the 13th with full moon. This time, my preference is for Emacs Lisp, and instead of re-implementing the same algorithm, I simply use the calculations already provided by Emacs. In other words, I rely on the lunar-phase-list function that returns the lunar phases of the upcoming dates given a month and a year.

It’s been ages since I’ve done Common Lisp programming and many years since I’ve practiced Emacs Lisp, so the code below is probably not optimal and idiomatic, but nevertheless it follows:

You can used the function defined above to see whether it is your “unlucky” day:

This will return “Good luck!” most of the time, luckily! 🙂

Can you come up with other ways of detecting Friday the 13th with full moon using existing utilities, such as GNU calendar program? Or, how would you calculate the next 10 Friday the 13ths that had full moon, using Emacs Lisp or some existing utility?

 

 
Leave a comment

Posted by on November 12, 2015 in Emacs, Lisp, Programlama

 

Tags: , ,

Is this the State of the Art for grammar checking on Linux in 21st century?


Recently, I’ve shared an article with a colleague of mine. The article had been published in a peer-reviewed journal and the contents were original and interesting. On the other hand, my colleague, being a meticulous reader of scientific texts, has immediately spotted a few simple grammar errors. It was very easy to blame the authors and editors for not correcting such errors before publication, but this triggered another question:

Why don’t we have open source and very high quality grammar checking software that is already integrated into major text editors such as VIM, Emacs, etc.?

Any user of recent version of MS Word is well aware of on-the-fly grammar checking, at least for English. But as many academicians know very well, many of them use LaTeX to typeset their articles and rely on either well-known text editors such as VIM and Emacs, or specialized software for handling LaTeX easily. Therefore, to tell these people “go and check your article using MS Word, or copy paste your article text to an online grammar checking service” does not make a lot of sense. Those methods are not convenient and thus not very usable by hundreds of thousands of scientists writing articles every day. But what would be the ideal way? The answer is simple in theory: We have high quality open source spell checkers, at least for English, and they have been already integrated into major text editors, therefore scientists who write in LaTeX have no excuse for spelling errors, it is simply a matter of activating the spell checker. If only they had similar software for grammar checking, it would be very straightforward and convenient to eliminate the easiest grammar errors, at least for English.

A quick search on the Internet revealed the following for grammar checking on GNU/Linux:

– Baoqiu Cui has implemented a grammar checker integration for Emacs using link-grammar, but unfortunately it is far from easily usable.

emacsGC1

Read the rest of this entry »

 
1 Comment

Posted by on June 10, 2014 in Emacs, Linguistics, Linux

 

Tags: , , , ,

Lean Text Editing with Emacs: Kanban Applied to the Process of Text Editing


The reader of this blog entry’s title might be ready for a long article, but sometimes the best things in life are very short and simple. Such as this subtle question and discovery of an Emacs user: Why don’t we eliminate waste of time by simply automating the white-space insertion after comma and most of the other punctuation characters?

Why, indeed? I’ve never thought of it before, yet, without giving it a single thought I’ve tortured my SPACE key millions of times. The solution? Simpy apply the following recipe to your beloved Emacs text editor, thereby adapting it to the Agile, Lean, and Kanban world of text editing by eliminating waste:

Read the rest of this entry »

 
2 Comments

Posted by on April 7, 2013 in Emacs, Programlama

 

Tags: , , , , , , ,

How to subtract a number from the current word and replace the result (in Emacs Lisp)


I needed to do some Emacs Lisp hacking for a little project (there are more conventional methods but they don’t have the sheer pleasure of hacking Lisp ;-)). Basically I wanted to come up with a function that takes the current word, converts it into an integer, subtracts some number from it, converts the resulting number into a string again and then replaces the original “word” with the new value:

 
Leave a comment

Posted by on December 20, 2011 in Emacs, Lisp, Programlama

 

Tags: , ,