Skip to content

Commit

Permalink
support "-*- mode -*-" declarations in load_file
Browse files Browse the repository at this point in the history
  • Loading branch information
mishoo committed Jul 16, 2011
1 parent 63a86e0 commit 95b516b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/js/ymacs-commands-utils.js
Expand Up @@ -39,6 +39,17 @@ Ymacs_Buffer.newCommands({
return this.getRegion(); return this.getRegion();
}, },


figure_out_mode: function(code) {
var lines = code.split(/\n/);
if (lines.length > 4)
lines.splice(2, lines.length - 4);
return lines.foreach(function(line, m){
if ((m = /-\*-\s*(.*?)\s*-\*-/i.exec(line))) {
$RETURN(m[1]);
}
});
},

cperl_lineup: Ymacs_Interactive("r", function(begin, end){ cperl_lineup: Ymacs_Interactive("r", function(begin, end){
this.cmd("save_excursion", function(){ this.cmd("save_excursion", function(){
var rcend = this._positionToRowCol(end), max = 0, lines = []; var rcend = this._positionToRowCol(end), max = 0, lines = [];
Expand Down Expand Up @@ -141,6 +152,14 @@ Ymacs_Buffer.newCommands({
var buffer = this.ymacs.createBuffer({ name: name }); var buffer = this.ymacs.createBuffer({ name: name });
buffer.setCode(code); buffer.setCode(code);
this.cmd("switch_to_buffer", name); this.cmd("switch_to_buffer", name);
var mode = this.cmd("figure_out_mode", code);
if (mode) {
if (Object.HOP(buffer.COMMANDS, mode)) {
buffer.cmd(mode);
} else if (Object.HOP(buffer.COMMANDS, mode + "_mode")) {
buffer.cmd(mode + "_mode");
}
}
}), }),


delete_file: Ymacs_Interactive("fDelete file: ", function(name){ delete_file: Ymacs_Interactive("fDelete file: ", function(name){
Expand Down

0 comments on commit 95b516b

Please sign in to comment.